You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by Patrick Kiernan <ho...@gmail.com> on 2009/04/10 14:11:23 UTC

Using Apache XMLSchema API

Hi,
Trying to start using the API. Following the instructions in the tutorial I
can get the schema to print fine.

However now I would like to start accessing elements.

I tried the following:


InputStream is = new FileInputStream("note.xsd");
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is), null);


XmlSchemaObjectTable objectTable = schema.getElements();

System.out.println(objectTable.getCount());


This prints out 0. Should it not print out the number of elements?


notes.xsd is as follows:



<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

</xs:schema>



Thanks,

Patrick

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Ok, thanks for your help.

On Thu, Apr 16, 2009 at 3:44 PM, Benson Margulies <bi...@gmail.com>wrote:

> You will have to read the source like the rest of us do if you want to
> get anywhere. XmlSchema does not have a body of doc or examples.
>
> On Thu, Apr 16, 2009 at 10:04 AM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > That doesnt work as getElements() returns an XmlObjectTable and this
> doesn't
> > have an interator() method
> > however it does have getNames() and getValues() which return iterators so
> > I've tried:
> >
> > XmlSchemaElement e =
> > (XmlSchemaElement)schema.getElements().getNames().next();
> >
> > error message: java.lang.ClassCastException: javax.xml.namespace.QName
> > cannot be cast to
> > org.apache.ws.commons.schema.XmlSchemaElement
> >
> > I've also tried:
> >
> > XmlSchemaElement e =
> > (XmlSchemaElement)schema.getElements().getValues().next();
> >
> > This works so I now have an XmlSchemaElement object called e.
> >
> > And from this you say to call getSchemaType to work my way down so I've
> > tried this however
> > I don't see how to return the names of the elements in the complex type
> ie.
> > to, from, heading, body.
> >
> > Thanks for your help with this, can you explain further please?
> >
> > On Thu, Apr 16, 2009 at 12:29 PM, Benson Margulies <
> bimargulies@gmail.com>wrote:
> >
> >> You cast the XmlSchemaItem to an XmlSchemaElement.
> >>
> >> XmlSchemaElement e =
> >> (XmlSchemaElement)schema.getElements().iterator().next();
> >>
> >> On Tu, Apr 16, 2009 at 7:27 AM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > I've tried:
> >> >
> >> > XmlSchemaObjectTable objectTable = schema.getElements();
> >> >
> >> > Now I can print the name of the element by doing:
> >> > Iterator it = objectTable.getNames();
> >> > System.out.println(it.next());
> >> >
> >> > Ok but how do I "obtain" the one element in my schema so that I can
> call
> >> > getSchemaType on
> >> > it like you suggest?
> >> >
> >> > On Thu, Apr 16, 2009 at 12:19 PM, Benson Margulies <
> >> bimargulies@gmail.com>wrote:
> >> >
> >> >> Same thing I explained before. The top-level collections contain only
> >> >> top-level objects. The one element in your schema is sitting in the
> >> >> items() collection, or in the elements collection. You obtain it, and
> >> >> call getSchemaType on it to work our way down.
> >> >>
> >> >> The data structures really mirror the XML.
> >> >>
> >> >>
> >> >> On Thu, Apr 16, 2009 at 7:11 AM, Patrick Kiernan <hossbert@gmail.com
> >
> >> >> wrote:
> >> >> > I'm not sure how to get the elements into an XmlSchemaElement
> object.
> >> >> > I have the schema in an object called "schema" of type XmlSchema.
> >> Looking
> >> >> at
> >> >> > the API
> >> >> > for methods on this and I see getSchemaTypes() which returns an
> >> >> > XmlSchemaObjectTable.
> >> >> > I've tried doing a getCount() on this but it returns 0 for the file
> >> I'm
> >> >> > testing.
> >> >> >
> >> >> > Can you explain further please?
> >> >> >
> >> >> > On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <
> >> bimargulies@gmail.com
> >> >> >wrote:
> >> >> >
> >> >> >> There are methods on XmlSchemaElement that returns the type name
> >> (when
> >> >> >> it's in another schema) or the type (when it's in the same
> schema).
> >> >> >> You want getSchemaType().
> >> >> >>
> >> >> >> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <
> hossbert@gmail.com
> >> >
> >> >> >> wrote:
> >> >> >> > Ok so I want to parse the notes.xsd file. When I say parse I
> would
> >> >> like
> >> >> >> to
> >> >> >> > extract
> >> >> >> > the following:
> >> >> >> >
> >> >> >> > note
> >> >> >> > to [string]
> >> >> >> > from [string]
> >> >> >> > heading [string]
> >> >> >> > body [string]
> >> >> >> >
> >> >> >> > So I'd like to extract the fact that the elements to, from,
> heading
> >> >> and
> >> >> >> body
> >> >> >> > are of type string. It
> >> >> >> > may be important to note that I am trying make my parser ask
> >> generic
> >> >> as
> >> >> >> > possible i.e. it will do this
> >> >> >> > for any schema file.
> >> >> >> >
> >> >> >> > The full file is available here:
> >> >> >> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> <http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> >> <
> >> >> >> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> >> >> >> >
> >> >> >> > So I've the following code:
> >> >> >> >
> >> >> >> > try{
> >> >> >> >               InputStream is = is = new
> >> >> >> >
> >> >> >>
> >> >>
> >>
> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
> >> >> >> >
> >> >> >> >               XmlSchemaCollection schemaCol = new
> >> >> XmlSchemaCollection();
> >> >> >> >               XmlSchema schema = schemaCol.read(new
> >> StreamSource(is),
> >> >> >> > null);
> >> >> >> >               XmlSchemaObjectTable objectTable =
> >> schema.getElements();
> >> >> >> >
> >> >> >> > So I have an object called schema. The methods getElements() and
> >> >> >> getItems()
> >> >> >> > both return note and not
> >> >> >> > the elements to, from, heading or body as they are in a sequence
> in
> >> a
> >> >> >> > complex type.
> >> >> >> >
> >> >> >> > You say to ask the elemnt for its type, how do I do this?
> >> >> >> >
> >> >> >> > Thanks,
> >> >> >> > Patrick
> >> >> >> >
> >> >> >> >
> >> >> >> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
> >> >> >> bimargulies@gmail.com>wrote:
> >> >> >> >
> >> >> >> >> You ask the element for its type. You cast the type to
> >> >> >> >> XmlSchemaComplexType.
> >> >> >> >>
> >> >> >> >> You ask it for for the particle.
> >> >> >> >>
> >> >> >> >> You cast that to XmlSchemaSequence.
> >> >> >> >>
> >> >> >> >> And the elements are in the sequence.
> >> >> >> >>
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
You will have to read the source like the rest of us do if you want to
get anywhere. XmlSchema does not have a body of doc or examples.

On Thu, Apr 16, 2009 at 10:04 AM, Patrick Kiernan <ho...@gmail.com> wrote:
> That doesnt work as getElements() returns an XmlObjectTable and this doesn't
> have an interator() method
> however it does have getNames() and getValues() which return iterators so
> I've tried:
>
> XmlSchemaElement e =
> (XmlSchemaElement)schema.getElements().getNames().next();
>
> error message: java.lang.ClassCastException: javax.xml.namespace.QName
> cannot be cast to
> org.apache.ws.commons.schema.XmlSchemaElement
>
> I've also tried:
>
> XmlSchemaElement e =
> (XmlSchemaElement)schema.getElements().getValues().next();
>
> This works so I now have an XmlSchemaElement object called e.
>
> And from this you say to call getSchemaType to work my way down so I've
> tried this however
> I don't see how to return the names of the elements in the complex type ie.
> to, from, heading, body.
>
> Thanks for your help with this, can you explain further please?
>
> On Thu, Apr 16, 2009 at 12:29 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> You cast the XmlSchemaItem to an XmlSchemaElement.
>>
>> XmlSchemaElement e =
>> (XmlSchemaElement)schema.getElements().iterator().next();
>>
>> On Tu, Apr 16, 2009 at 7:27 AM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > I've tried:
>> >
>> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >
>> > Now I can print the name of the element by doing:
>> > Iterator it = objectTable.getNames();
>> > System.out.println(it.next());
>> >
>> > Ok but how do I "obtain" the one element in my schema so that I can call
>> > getSchemaType on
>> > it like you suggest?
>> >
>> > On Thu, Apr 16, 2009 at 12:19 PM, Benson Margulies <
>> bimargulies@gmail.com>wrote:
>> >
>> >> Same thing I explained before. The top-level collections contain only
>> >> top-level objects. The one element in your schema is sitting in the
>> >> items() collection, or in the elements collection. You obtain it, and
>> >> call getSchemaType on it to work our way down.
>> >>
>> >> The data structures really mirror the XML.
>> >>
>> >>
>> >> On Thu, Apr 16, 2009 at 7:11 AM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > I'm not sure how to get the elements into an XmlSchemaElement object.
>> >> > I have the schema in an object called "schema" of type XmlSchema.
>> Looking
>> >> at
>> >> > the API
>> >> > for methods on this and I see getSchemaTypes() which returns an
>> >> > XmlSchemaObjectTable.
>> >> > I've tried doing a getCount() on this but it returns 0 for the file
>> I'm
>> >> > testing.
>> >> >
>> >> > Can you explain further please?
>> >> >
>> >> > On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <
>> bimargulies@gmail.com
>> >> >wrote:
>> >> >
>> >> >> There are methods on XmlSchemaElement that returns the type name
>> (when
>> >> >> it's in another schema) or the type (when it's in the same schema).
>> >> >> You want getSchemaType().
>> >> >>
>> >> >> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <hossbert@gmail.com
>> >
>> >> >> wrote:
>> >> >> > Ok so I want to parse the notes.xsd file. When I say parse I would
>> >> like
>> >> >> to
>> >> >> > extract
>> >> >> > the following:
>> >> >> >
>> >> >> > note
>> >> >> > to [string]
>> >> >> > from [string]
>> >> >> > heading [string]
>> >> >> > body [string]
>> >> >> >
>> >> >> > So I'd like to extract the fact that the elements to, from, heading
>> >> and
>> >> >> body
>> >> >> > are of type string. It
>> >> >> > may be important to note that I am trying make my parser ask
>> generic
>> >> as
>> >> >> > possible i.e. it will do this
>> >> >> > for any schema file.
>> >> >> >
>> >> >> > The full file is available here:
>> >> >> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
>> <
>> >> >> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
>> >> >> >
>> >> >> > So I've the following code:
>> >> >> >
>> >> >> > try{
>> >> >> >               InputStream is = is = new
>> >> >> >
>> >> >>
>> >>
>> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>> >> >> >
>> >> >> >               XmlSchemaCollection schemaCol = new
>> >> XmlSchemaCollection();
>> >> >> >               XmlSchema schema = schemaCol.read(new
>> StreamSource(is),
>> >> >> > null);
>> >> >> >               XmlSchemaObjectTable objectTable =
>> schema.getElements();
>> >> >> >
>> >> >> > So I have an object called schema. The methods getElements() and
>> >> >> getItems()
>> >> >> > both return note and not
>> >> >> > the elements to, from, heading or body as they are in a sequence in
>> a
>> >> >> > complex type.
>> >> >> >
>> >> >> > You say to ask the elemnt for its type, how do I do this?
>> >> >> >
>> >> >> > Thanks,
>> >> >> > Patrick
>> >> >> >
>> >> >> >
>> >> >> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
>> >> >> bimargulies@gmail.com>wrote:
>> >> >> >
>> >> >> >> You ask the element for its type. You cast the type to
>> >> >> >> XmlSchemaComplexType.
>> >> >> >>
>> >> >> >> You ask it for for the particle.
>> >> >> >>
>> >> >> >> You cast that to XmlSchemaSequence.
>> >> >> >>
>> >> >> >> And the elements are in the sequence.
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
That doesnt work as getElements() returns an XmlObjectTable and this doesn't
have an interator() method
however it does have getNames() and getValues() which return iterators so
I've tried:

XmlSchemaElement e =
(XmlSchemaElement)schema.getElements().getNames().next();

error message: java.lang.ClassCastException: javax.xml.namespace.QName
cannot be cast to
org.apache.ws.commons.schema.XmlSchemaElement

I've also tried:

XmlSchemaElement e =
(XmlSchemaElement)schema.getElements().getValues().next();

This works so I now have an XmlSchemaElement object called e.

And from this you say to call getSchemaType to work my way down so I've
tried this however
I don't see how to return the names of the elements in the complex type ie.
to, from, heading, body.

Thanks for your help with this, can you explain further please?

On Thu, Apr 16, 2009 at 12:29 PM, Benson Margulies <bi...@gmail.com>wrote:

> You cast the XmlSchemaItem to an XmlSchemaElement.
>
> XmlSchemaElement e =
> (XmlSchemaElement)schema.getElements().iterator().next();
>
> On Tu, Apr 16, 2009 at 7:27 AM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > I've tried:
> >
> > XmlSchemaObjectTable objectTable = schema.getElements();
> >
> > Now I can print the name of the element by doing:
> > Iterator it = objectTable.getNames();
> > System.out.println(it.next());
> >
> > Ok but how do I "obtain" the one element in my schema so that I can call
> > getSchemaType on
> > it like you suggest?
> >
> > On Thu, Apr 16, 2009 at 12:19 PM, Benson Margulies <
> bimargulies@gmail.com>wrote:
> >
> >> Same thing I explained before. The top-level collections contain only
> >> top-level objects. The one element in your schema is sitting in the
> >> items() collection, or in the elements collection. You obtain it, and
> >> call getSchemaType on it to work our way down.
> >>
> >> The data structures really mirror the XML.
> >>
> >>
> >> On Thu, Apr 16, 2009 at 7:11 AM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > I'm not sure how to get the elements into an XmlSchemaElement object.
> >> > I have the schema in an object called "schema" of type XmlSchema.
> Looking
> >> at
> >> > the API
> >> > for methods on this and I see getSchemaTypes() which returns an
> >> > XmlSchemaObjectTable.
> >> > I've tried doing a getCount() on this but it returns 0 for the file
> I'm
> >> > testing.
> >> >
> >> > Can you explain further please?
> >> >
> >> > On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <
> bimargulies@gmail.com
> >> >wrote:
> >> >
> >> >> There are methods on XmlSchemaElement that returns the type name
> (when
> >> >> it's in another schema) or the type (when it's in the same schema).
> >> >> You want getSchemaType().
> >> >>
> >> >> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <hossbert@gmail.com
> >
> >> >> wrote:
> >> >> > Ok so I want to parse the notes.xsd file. When I say parse I would
> >> like
> >> >> to
> >> >> > extract
> >> >> > the following:
> >> >> >
> >> >> > note
> >> >> > to [string]
> >> >> > from [string]
> >> >> > heading [string]
> >> >> > body [string]
> >> >> >
> >> >> > So I'd like to extract the fact that the elements to, from, heading
> >> and
> >> >> body
> >> >> > are of type string. It
> >> >> > may be important to note that I am trying make my parser ask
> generic
> >> as
> >> >> > possible i.e. it will do this
> >> >> > for any schema file.
> >> >> >
> >> >> > The full file is available here:
> >> >> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> <
> >> >> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> >> >> >
> >> >> > So I've the following code:
> >> >> >
> >> >> > try{
> >> >> >               InputStream is = is = new
> >> >> >
> >> >>
> >>
> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
> >> >> >
> >> >> >               XmlSchemaCollection schemaCol = new
> >> XmlSchemaCollection();
> >> >> >               XmlSchema schema = schemaCol.read(new
> StreamSource(is),
> >> >> > null);
> >> >> >               XmlSchemaObjectTable objectTable =
> schema.getElements();
> >> >> >
> >> >> > So I have an object called schema. The methods getElements() and
> >> >> getItems()
> >> >> > both return note and not
> >> >> > the elements to, from, heading or body as they are in a sequence in
> a
> >> >> > complex type.
> >> >> >
> >> >> > You say to ask the elemnt for its type, how do I do this?
> >> >> >
> >> >> > Thanks,
> >> >> > Patrick
> >> >> >
> >> >> >
> >> >> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
> >> >> bimargulies@gmail.com>wrote:
> >> >> >
> >> >> >> You ask the element for its type. You cast the type to
> >> >> >> XmlSchemaComplexType.
> >> >> >>
> >> >> >> You ask it for for the particle.
> >> >> >>
> >> >> >> You cast that to XmlSchemaSequence.
> >> >> >>
> >> >> >> And the elements are in the sequence.
> >> >> >>
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
You cast the XmlSchemaItem to an XmlSchemaElement.

XmlSchemaElement e = (XmlSchemaElement)schema.getElements().iterator().next();

On Tu, Apr 16, 2009 at 7:27 AM, Patrick Kiernan <ho...@gmail.com> wrote:
> I've tried:
>
> XmlSchemaObjectTable objectTable = schema.getElements();
>
> Now I can print the name of the element by doing:
> Iterator it = objectTable.getNames();
> System.out.println(it.next());
>
> Ok but how do I "obtain" the one element in my schema so that I can call
> getSchemaType on
> it like you suggest?
>
> On Thu, Apr 16, 2009 at 12:19 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> Same thing I explained before. The top-level collections contain only
>> top-level objects. The one element in your schema is sitting in the
>> items() collection, or in the elements collection. You obtain it, and
>> call getSchemaType on it to work our way down.
>>
>> The data structures really mirror the XML.
>>
>>
>> On Thu, Apr 16, 2009 at 7:11 AM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > I'm not sure how to get the elements into an XmlSchemaElement object.
>> > I have the schema in an object called "schema" of type XmlSchema. Looking
>> at
>> > the API
>> > for methods on this and I see getSchemaTypes() which returns an
>> > XmlSchemaObjectTable.
>> > I've tried doing a getCount() on this but it returns 0 for the file I'm
>> > testing.
>> >
>> > Can you explain further please?
>> >
>> > On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <bimargulies@gmail.com
>> >wrote:
>> >
>> >> There are methods on XmlSchemaElement that returns the type name (when
>> >> it's in another schema) or the type (when it's in the same schema).
>> >> You want getSchemaType().
>> >>
>> >> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > Ok so I want to parse the notes.xsd file. When I say parse I would
>> like
>> >> to
>> >> > extract
>> >> > the following:
>> >> >
>> >> > note
>> >> > to [string]
>> >> > from [string]
>> >> > heading [string]
>> >> > body [string]
>> >> >
>> >> > So I'd like to extract the fact that the elements to, from, heading
>> and
>> >> body
>> >> > are of type string. It
>> >> > may be important to note that I am trying make my parser ask generic
>> as
>> >> > possible i.e. it will do this
>> >> > for any schema file.
>> >> >
>> >> > The full file is available here:
>> >> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<
>> >> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
>> >> >
>> >> > So I've the following code:
>> >> >
>> >> > try{
>> >> >               InputStream is = is = new
>> >> >
>> >>
>> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>> >> >
>> >> >               XmlSchemaCollection schemaCol = new
>> XmlSchemaCollection();
>> >> >               XmlSchema schema = schemaCol.read(new StreamSource(is),
>> >> > null);
>> >> >               XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >
>> >> > So I have an object called schema. The methods getElements() and
>> >> getItems()
>> >> > both return note and not
>> >> > the elements to, from, heading or body as they are in a sequence in a
>> >> > complex type.
>> >> >
>> >> > You say to ask the elemnt for its type, how do I do this?
>> >> >
>> >> > Thanks,
>> >> > Patrick
>> >> >
>> >> >
>> >> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
>> >> bimargulies@gmail.com>wrote:
>> >> >
>> >> >> You ask the element for its type. You cast the type to
>> >> >> XmlSchemaComplexType.
>> >> >>
>> >> >> You ask it for for the particle.
>> >> >>
>> >> >> You cast that to XmlSchemaSequence.
>> >> >>
>> >> >> And the elements are in the sequence.
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
I've tried:

XmlSchemaObjectTable objectTable = schema.getElements();

Now I can print the name of the element by doing:
Iterator it = objectTable.getNames();
System.out.println(it.next());

Ok but how do I "obtain" the one element in my schema so that I can call
getSchemaType on
it like you suggest?

On Thu, Apr 16, 2009 at 12:19 PM, Benson Margulies <bi...@gmail.com>wrote:

> Same thing I explained before. The top-level collections contain only
> top-level objects. The one element in your schema is sitting in the
> items() collection, or in the elements collection. You obtain it, and
> call getSchemaType on it to work our way down.
>
> The data structures really mirror the XML.
>
>
> On Thu, Apr 16, 2009 at 7:11 AM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > I'm not sure how to get the elements into an XmlSchemaElement object.
> > I have the schema in an object called "schema" of type XmlSchema. Looking
> at
> > the API
> > for methods on this and I see getSchemaTypes() which returns an
> > XmlSchemaObjectTable.
> > I've tried doing a getCount() on this but it returns 0 for the file I'm
> > testing.
> >
> > Can you explain further please?
> >
> > On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <bimargulies@gmail.com
> >wrote:
> >
> >> There are methods on XmlSchemaElement that returns the type name (when
> >> it's in another schema) or the type (when it's in the same schema).
> >> You want getSchemaType().
> >>
> >> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > Ok so I want to parse the notes.xsd file. When I say parse I would
> like
> >> to
> >> > extract
> >> > the following:
> >> >
> >> > note
> >> > to [string]
> >> > from [string]
> >> > heading [string]
> >> > body [string]
> >> >
> >> > So I'd like to extract the fact that the elements to, from, heading
> and
> >> body
> >> > are of type string. It
> >> > may be important to note that I am trying make my parser ask generic
> as
> >> > possible i.e. it will do this
> >> > for any schema file.
> >> >
> >> > The full file is available here:
> >> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<
> >> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> >> >
> >> > So I've the following code:
> >> >
> >> > try{
> >> >               InputStream is = is = new
> >> >
> >>
> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
> >> >
> >> >               XmlSchemaCollection schemaCol = new
> XmlSchemaCollection();
> >> >               XmlSchema schema = schemaCol.read(new StreamSource(is),
> >> > null);
> >> >               XmlSchemaObjectTable objectTable = schema.getElements();
> >> >
> >> > So I have an object called schema. The methods getElements() and
> >> getItems()
> >> > both return note and not
> >> > the elements to, from, heading or body as they are in a sequence in a
> >> > complex type.
> >> >
> >> > You say to ask the elemnt for its type, how do I do this?
> >> >
> >> > Thanks,
> >> > Patrick
> >> >
> >> >
> >> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
> >> bimargulies@gmail.com>wrote:
> >> >
> >> >> You ask the element for its type. You cast the type to
> >> >> XmlSchemaComplexType.
> >> >>
> >> >> You ask it for for the particle.
> >> >>
> >> >> You cast that to XmlSchemaSequence.
> >> >>
> >> >> And the elements are in the sequence.
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
Same thing I explained before. The top-level collections contain only
top-level objects. The one element in your schema is sitting in the
items() collection, or in the elements collection. You obtain it, and
call getSchemaType on it to work our way down.

The data structures really mirror the XML.


On Thu, Apr 16, 2009 at 7:11 AM, Patrick Kiernan <ho...@gmail.com> wrote:
> I'm not sure how to get the elements into an XmlSchemaElement object.
> I have the schema in an object called "schema" of type XmlSchema. Looking at
> the API
> for methods on this and I see getSchemaTypes() which returns an
> XmlSchemaObjectTable.
> I've tried doing a getCount() on this but it returns 0 for the file I'm
> testing.
>
> Can you explain further please?
>
> On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> There are methods on XmlSchemaElement that returns the type name (when
>> it's in another schema) or the type (when it's in the same schema).
>> You want getSchemaType().
>>
>> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Ok so I want to parse the notes.xsd file. When I say parse I would like
>> to
>> > extract
>> > the following:
>> >
>> > note
>> > to [string]
>> > from [string]
>> > heading [string]
>> > body [string]
>> >
>> > So I'd like to extract the fact that the elements to, from, heading and
>> body
>> > are of type string. It
>> > may be important to note that I am trying make my parser ask generic as
>> > possible i.e. it will do this
>> > for any schema file.
>> >
>> > The full file is available here:
>> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<
>> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
>> >
>> > So I've the following code:
>> >
>> > try{
>> >               InputStream is = is = new
>> >
>> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>> >
>> >               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >               XmlSchema schema = schemaCol.read(new StreamSource(is),
>> > null);
>> >               XmlSchemaObjectTable objectTable = schema.getElements();
>> >
>> > So I have an object called schema. The methods getElements() and
>> getItems()
>> > both return note and not
>> > the elements to, from, heading or body as they are in a sequence in a
>> > complex type.
>> >
>> > You say to ask the elemnt for its type, how do I do this?
>> >
>> > Thanks,
>> > Patrick
>> >
>> >
>> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
>> bimargulies@gmail.com>wrote:
>> >
>> >> You ask the element for its type. You cast the type to
>> >> XmlSchemaComplexType.
>> >>
>> >> You ask it for for the particle.
>> >>
>> >> You cast that to XmlSchemaSequence.
>> >>
>> >> And the elements are in the sequence.
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
I'm not sure how to get the elements into an XmlSchemaElement object.
I have the schema in an object called "schema" of type XmlSchema. Looking at
the API
for methods on this and I see getSchemaTypes() which returns an
XmlSchemaObjectTable.
I've tried doing a getCount() on this but it returns 0 for the file I'm
testing.

Can you explain further please?

On Wed, Apr 15, 2009 at 7:50 PM, Benson Margulies <bi...@gmail.com>wrote:

> There are methods on XmlSchemaElement that returns the type name (when
> it's in another schema) or the type (when it's in the same schema).
> You want getSchemaType().
>
> On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > Ok so I want to parse the notes.xsd file. When I say parse I would like
> to
> > extract
> > the following:
> >
> > note
> > to [string]
> > from [string]
> > heading [string]
> > body [string]
> >
> > So I'd like to extract the fact that the elements to, from, heading and
> body
> > are of type string. It
> > may be important to note that I am trying make my parser ask generic as
> > possible i.e. it will do this
> > for any schema file.
> >
> > The full file is available here:
> > http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<
> http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
> >
> > So I've the following code:
> >
> > try{
> >               InputStream is = is = new
> >
> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
> >
> >               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >               XmlSchema schema = schemaCol.read(new StreamSource(is),
> > null);
> >               XmlSchemaObjectTable objectTable = schema.getElements();
> >
> > So I have an object called schema. The methods getElements() and
> getItems()
> > both return note and not
> > the elements to, from, heading or body as they are in a sequence in a
> > complex type.
> >
> > You say to ask the elemnt for its type, how do I do this?
> >
> > Thanks,
> > Patrick
> >
> >
> > On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <
> bimargulies@gmail.com>wrote:
> >
> >> You ask the element for its type. You cast the type to
> >> XmlSchemaComplexType.
> >>
> >> You ask it for for the particle.
> >>
> >> You cast that to XmlSchemaSequence.
> >>
> >> And the elements are in the sequence.
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
There are methods on XmlSchemaElement that returns the type name (when
it's in another schema) or the type (when it's in the same schema).
You want getSchemaType().

On Wed, Apr 15, 2009 at 9:23 AM, Patrick Kiernan <ho...@gmail.com> wrote:
> Ok so I want to parse the notes.xsd file. When I say parse I would like to
> extract
> the following:
>
> note
> to [string]
> from [string]
> heading [string]
> body [string]
>
> So I'd like to extract the fact that the elements to, from, heading and body
> are of type string. It
> may be important to note that I am trying make my parser ask generic as
> possible i.e. it will do this
> for any schema file.
>
> The full file is available here:
> http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>
>
> So I've the following code:
>
> try{
>               InputStream is = is = new
> FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>
>               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>               XmlSchema schema = schemaCol.read(new StreamSource(is),
> null);
>               XmlSchemaObjectTable objectTable = schema.getElements();
>
> So I have an object called schema. The methods getElements() and getItems()
> both return note and not
> the elements to, from, heading or body as they are in a sequence in a
> complex type.
>
> You say to ask the elemnt for its type, how do I do this?
>
> Thanks,
> Patrick
>
>
> On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> You ask the element for its type. You cast the type to
>> XmlSchemaComplexType.
>>
>> You ask it for for the particle.
>>
>> You cast that to XmlSchemaSequence.
>>
>> And the elements are in the sequence.
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Ok so I want to parse the notes.xsd file. When I say parse I would like to
extract
the following:

note
to [string]
from [string]
heading [string]
body [string]

So I'd like to extract the fact that the elements to, from, heading and body
are of type string. It
may be important to note that I am trying make my parser ask generic as
possible i.e. it will do this
for any schema file.

The full file is available here:
http://www.redbrick.dcu.ie/~hoss/uploads/note.xsd<http://www.redbrick.dcu.ie/%7Ehoss/uploads/note.xsd>

So I've the following code:

try{
               InputStream is = is = new
FileInputStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");

               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
               XmlSchema schema = schemaCol.read(new StreamSource(is),
null);
               XmlSchemaObjectTable objectTable = schema.getElements();

So I have an object called schema. The methods getElements() and getItems()
both return note and not
the elements to, from, heading or body as they are in a sequence in a
complex type.

You say to ask the elemnt for its type, how do I do this?

Thanks,
Patrick


On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <bi...@gmail.com>wrote:

> You ask the element for its type. You cast the type to
> XmlSchemaComplexType.
>
> You ask it for for the particle.
>
> You cast that to XmlSchemaSequence.
>
> And the elements are in the sequence.
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Will try this tomorrow thanks

On Fri, Apr 10, 2009 at 10:38 PM, Benson Margulies <bi...@gmail.com>wrote:

> You ask the element for its type. You cast the type to
> XmlSchemaComplexType.
>
> You ask it for for the particle.
>
> You cast that to XmlSchemaSequence.
>
> And the elements are in the sequence.
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
You ask the element for its type. You cast the type to XmlSchemaComplexType.

You ask it for for the particle.

You cast that to XmlSchemaSequence.

And the elements are in the sequence.

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Ok strangely I commented out xsdParser.printSchema(), compiled and ran it
and itprinted 1!! I uncommented xsdParser.printSchema() and it still prints
1 so it's working
now!

Thanks for your help!


On Fri, Apr 10, 2009 at 10:47 PM, Patrick Kiernan <ho...@gmail.com>wrote:

> Ok that works now and it prints 1 for the answer which is correct. Finally!
> The different with my other program is I have the following class:
>
>
> package schemaparser;
>
> import java.io.*;
>
> import javax.xml.transform.stream.StreamSource;
> import org.apache.ws.commons.schema.*;
>
> public class XSDParser {
>
>     private InputStream is;
>     private XmlSchemaCollection schemaCol;
>     private XmlSchema schema;
>
>     public XSDParser(String fileName){
>         try {
>             is = new FileInputStream(fileName);
>             schemaCol = new XmlSchemaCollection();
>             schema = schemaCol.read(new StreamSource(is), null);
>         } catch (FileNotFoundException ex) {
>             ex.printStackTrace();
>         }
>     }
>
>     public void printSchema(){
>         schema.write(System.out);
>     }
>
>     public int getRootNode(){
>         //XmlSchemaObjectTable attribsObjTbl = schema.getAttributes();
>         XmlSchemaObjectTable elementsObjTbl = schema.getElements();
>
>         return elementsObjTbl.getCount();
>
>     }
>
> }
>
> And the following class:
>
> package schemaparser;
>
> public class XMLSchemaTest {
>
>     public static void main(String [] args) {
>
>         XSDParser xsdParser = new
> XSDParser("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>
>          xsdParser.printSchema();
>
>         System.out.println(xsdParser.getRootNode());
>     }
>
> }
>
> And for some reason here it prints zero!
>
> On Fri, Apr 10, 2009 at 10:33 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> Yes. GetResourceAsStream takes classpath names, not file system
>> pathnames. Stick with FileInputStream for those.
>>
>> More in a minute ...
>>
>>
>> On Fri, Apr 10, 2009 at 5:31 PM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Ok fair enough. How do you access the elements in the sequence? ie.
>> extract
>> > their names?
>> > I just tried your test case as a java class:
>> >
>> > package schemaparser;
>> >
>> > import java.io.InputStream;
>> >
>> > import javax.xml.transform.stream.StreamSource;
>> >
>> > import org.apache.ws.commons.schema.XmlSchema;
>> > import org.apache.ws.commons.schema.XmlSchemaCollection;
>> > import org.apache.ws.commons.schema.XmlSchemaObjectTable;
>> >
>> >
>> > public class XSDSchemaTest2  {
>> >
>> >       public static void main(String [] args){
>> >
>> >           try{
>> >               InputStream is =
>> >                       XSDSchemaTest2.class.
>> >
>> >
>> getClassLoader().getResourceAsStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>> >               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >               XmlSchema schema = schemaCol.read(new StreamSource(is),
>> > null);
>> >               XmlSchemaObjectTable objectTable = schema.getElements();
>> >               System.out.println(objectTable.getCount());
>> >           } catch(Exception ex){
>> >               ex.printStackTrace();
>> >           }
>> >
>> >       }
>> > }
>> >
>> > When I try and run that I get the following error:
>> >
>> > org.apache.ws.commons.schema.XmlSchemaException
>> >        at
>> >
>> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:386)
>> >        at
>> >
>> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:422)
>> >        at
>> >
>> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:448)
>> >        at schemaparser.XSDSchemaTest2.main(XSDSchemaTest2.java:23)
>> >
>> > Any idea what's wrong there?
>> >
>> > Thanks,
>> > Patrick
>> >
>> > On Fri, Apr 10, 2009 at 10:26 PM, Benson Margulies <
>> bimargulies@gmail.com>wrote:
>> >
>> >> Oh! I completely misunderstood the question.
>> >>
>> >> Only top-level elements go into the collections. The elements inside a
>> >> sequence do not. So those elements are not supposed to be in items or
>> >> the elements object table. After all, you could have seven different
>> >> elements named 'to' inside of seven different complex types.
>> >>
>> >>
>> >>
>> >> On Fri, Apr 10, 2009 at 5:22 PM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > Yes I just saw your commit and the file you uploaded is the full copy
>> of
>> >> > notes.xsd:
>> >> > +<?xml version="1.0"?>
>> >> > +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> > +
>> >> > +<xs:element name="note">
>> >> > + <xs:complexType>
>> >> > +   <xs:sequence>
>> >> > +     <xs:element name="to" type="xs:string"/>
>> >> > +     <xs:element name="from" type="xs:string"/>
>> >> > +     <xs:element name="heading" type="xs:string"/>
>> >> > +     <xs:element name="body" type="xs:string"/>
>> >> > +   </xs:sequence>
>> >> > + </xs:complexType>
>> >> > +</xs:element>
>> >> > +
>> >> > +</xs:schema>
>> >> >
>> >> >
>> >> > On Fri, Apr 10, 2009 at 10:18 PM, Benson Margulies <
>> >> bimargulies@gmail.com>wrote:
>> >> >
>> >> >> I don't have a full copy of 'notes.xsd'. I just have the fragment
>> from
>> >> >> your first message. To give me a whole file, make a JIRA and attach
>> >> >> it. I just committed my unit test: grab the source tree from svn and
>> >> >> look at
>> >> >>
>> >> >> /XmlSchema/src/test/java/tests/SingleElementNoNamespace.java
>> >> >>
>> >> >> The svn path you want is
>> >> >>
>> >> >>
>> >> >>
>> >>
>> http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <
>> hossbert@gmail.com>
>> >> >> wrote:
>> >> >> > JDK is 6
>> >> >> > Don't have anything special in my classpath:
>> >> >> > .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
>> >> >> > files\java\jdk1.6.0_10\lib
>> >> >> >
>> >> >> > I don't have maven so I can't make a self-contained failing case
>> using
>> >> >> > maven.
>> >> >> >
>> >> >> > Is one member not incorrect since note.xsd has 5 elements:
>> >> >> >
>> >> >> > note
>> >> >> > to
>> >> >> > from
>> >> >> > heading
>> >> >> > body
>> >> >> >
>> >> >> > Can you provide your code please?
>> >> >> >
>> >> >> > Thanks,
>> >> >> > Patrick
>> >> >> >
>> >> >> > On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <
>> >> >> bimargulies@gmail.com>wrote:
>> >> >> >
>> >> >> >> I just turned your code into a unit test, and it worked. The
>> items
>> >> >> >> collection comes up with one member, as does the elements object
>> >> >> >> table.
>> >> >> >>
>> >> >> >> So, we have to look for some more interesting explanation. What
>> JDK?
>> >> >> >> Anything fancy in your class path, like a specific version of
>> Xerces
>> >> >> >> or some other alternative parser?
>> >> >> >>
>> >> >> >> Can you make a self-contained failing case using maven to specify
>> all
>> >> >> >> the dependencies?
>> >> >> >>
>> >> >> >> It is remotely possible that you've hit something fixed since
>> 1.4.4,
>> >> >> >> but very little has changed since then, and nothing in this
>> >> >> >> neighborhood.
>> >> >> >>
>> >> >> >>
>> >> >> >> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <
>> hossbert@gmail.com
>> >> >
>> >> >> >> wrote:
>> >> >> >> > I assumes that's:
>> >> >> >> >
>> >> >> >> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
>> >> >> >> > System.out.println(elementsObjTbl.getCount());
>> >> >> >> >
>> >> >> >> > That's also empty.
>> >> >> >> >
>> >> >> >> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <
>> >> >> bimargulies@gmail.com
>> >> >> >> >wrote:
>> >> >> >> >
>> >> >> >> >> I would expect that code of yours to work. My only suggestion
>> >> before
>> >> >> I
>> >> >> >> >> debug is that you get the element collection and see if THAT
>> is
>> >> also
>> >> >> >> >> empty.
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <
>> >> hossbert@gmail.com
>> >> >> >
>> >> >> >> >> wrote:
>> >> >> >> >> > Cool, thanks :)
>> >> >> >> >> > Is it a bug or?
>> >> >> >> >> >
>> >> >> >> >> > Maybe you could include some code showing the common uses of
>> the
>> >> >> API.
>> >> >> >> >> >
>> >> >> >> >> > I basically want to be able to extract the elements of a
>> schema
>> >> and
>> >> >> >> then
>> >> >> >> >> > display it using a
>> >> >> >> >> > JTree.
>> >> >> >> >> >
>> >> >> >> >> > Patrick
>> >> >> >> >> >
>> >> >> >> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
>> >> >> >> bimargulies@gmail.com
>> >> >> >> >> >wrote:
>> >> >> >> >> >
>> >> >> >> >> >> I'm a bit buried under Passover, but I'll sort this out
>> over
>> >> the
>> >> >> >> >> >> weekend some time.
>> >> >> >> >> >>
>> >> >> >> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
>> >> >> >> hossbert@gmail.com>
>> >> >> >> >> >> wrote:
>> >> >> >> >> >> > Version 1.4.4
>> >> >> >> >> >> >
>> >> >> >> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
>> >> >> >> >> bimargulies@gmail.com
>> >> >> >> >> >> >wrote:
>> >> >> >> >> >> >
>> >> >> >> >> >> >> You don't have a target namespace.... but that should be
>> OK.
>> >> >> What
>> >> >> >> >> >> >> version have you grabbed?
>> >> >> >> >> >> >>
>> >> >> >> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
>> >> >> >> hossbert@gmail.com
>> >> >> >> >> >
>> >> >> >> >> >> >> wrote:
>> >> >> >> >> >> >> > Hi,
>> >> >> >> >> >> >> > Trying to start using the API. Following the
>> instructions
>> >> in
>> >> >> the
>> >> >> >> >> >> tutorial
>> >> >> >> >> >> >> I
>> >> >> >> >> >> >> > can get the schema to print fine.
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > However now I would like to start accessing elements.
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > I tried the following:
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > InputStream is = new FileInputStream("note.xsd");
>> >> >> >> >> >> >> > XmlSchemaCollection schemaCol = new
>> XmlSchemaCollection();
>> >> >> >> >> >> >> > XmlSchema schema = schemaCol.read(new
>> StreamSource(is),
>> >> >> null);
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > XmlSchemaObjectTable objectTable =
>> schema.getElements();
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > System.out.println(objectTable.getCount());
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > This prints out 0. Should it not print out the number
>> of
>> >> >> >> elements?
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > notes.xsd is as follows:
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > <?xml version="1.0"?>
>> >> >> >> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema
>> ">
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > <xs:element name="note">
>> >> >> >> >> >> >> >  <xs:complexType>
>> >> >> >> >> >> >> >    <xs:sequence>
>> >> >> >> >> >> >> >      <xs:element name="to" type="xs:string"/>
>> >> >> >> >> >> >> >      <xs:element name="from" type="xs:string"/>
>> >> >> >> >> >> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >> >> >> >> >> >      <xs:element name="body" type="xs:string"/>
>> >> >> >> >> >> >> >    </xs:sequence>
>> >> >> >> >> >> >> >  </xs:complexType>
>> >> >> >> >> >> >> > </xs:element>
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > </xs:schema>
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > Thanks,
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >> > Patrick
>> >> >> >> >> >> >> >
>> >> >> >> >> >> >>
>> >> >> >> >> >> >
>> >> >> >> >> >>
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Ok that works now and it prints 1 for the answer which is correct. Finally!
The different with my other program is I have the following class:


package schemaparser;

import java.io.*;

import javax.xml.transform.stream.StreamSource;
import org.apache.ws.commons.schema.*;

public class XSDParser {

    private InputStream is;
    private XmlSchemaCollection schemaCol;
    private XmlSchema schema;

    public XSDParser(String fileName){
        try {
            is = new FileInputStream(fileName);
            schemaCol = new XmlSchemaCollection();
            schema = schemaCol.read(new StreamSource(is), null);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    public void printSchema(){
        schema.write(System.out);
    }

    public int getRootNode(){
        //XmlSchemaObjectTable attribsObjTbl = schema.getAttributes();
        XmlSchemaObjectTable elementsObjTbl = schema.getElements();

        return elementsObjTbl.getCount();

    }

}

And the following class:

package schemaparser;

public class XMLSchemaTest {

    public static void main(String [] args) {

        XSDParser xsdParser = new
XSDParser("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");

        xsdParser.printSchema();

        System.out.println(xsdParser.getRootNode());
    }

}

And for some reason here it prints zero!

On Fri, Apr 10, 2009 at 10:33 PM, Benson Margulies <bi...@gmail.com>wrote:

> Yes. GetResourceAsStream takes classpath names, not file system
> pathnames. Stick with FileInputStream for those.
>
> More in a minute ...
>
>
> On Fri, Apr 10, 2009 at 5:31 PM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > Ok fair enough. How do you access the elements in the sequence? ie.
> extract
> > their names?
> > I just tried your test case as a java class:
> >
> > package schemaparser;
> >
> > import java.io.InputStream;
> >
> > import javax.xml.transform.stream.StreamSource;
> >
> > import org.apache.ws.commons.schema.XmlSchema;
> > import org.apache.ws.commons.schema.XmlSchemaCollection;
> > import org.apache.ws.commons.schema.XmlSchemaObjectTable;
> >
> >
> > public class XSDSchemaTest2  {
> >
> >       public static void main(String [] args){
> >
> >           try{
> >               InputStream is =
> >                       XSDSchemaTest2.class.
> >
> >
> getClassLoader().getResourceAsStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
> >               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >               XmlSchema schema = schemaCol.read(new StreamSource(is),
> > null);
> >               XmlSchemaObjectTable objectTable = schema.getElements();
> >               System.out.println(objectTable.getCount());
> >           } catch(Exception ex){
> >               ex.printStackTrace();
> >           }
> >
> >       }
> > }
> >
> > When I try and run that I get the following error:
> >
> > org.apache.ws.commons.schema.XmlSchemaException
> >        at
> >
> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:386)
> >        at
> >
> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:422)
> >        at
> >
> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:448)
> >        at schemaparser.XSDSchemaTest2.main(XSDSchemaTest2.java:23)
> >
> > Any idea what's wrong there?
> >
> > Thanks,
> > Patrick
> >
> > On Fri, Apr 10, 2009 at 10:26 PM, Benson Margulies <
> bimargulies@gmail.com>wrote:
> >
> >> Oh! I completely misunderstood the question.
> >>
> >> Only top-level elements go into the collections. The elements inside a
> >> sequence do not. So those elements are not supposed to be in items or
> >> the elements object table. After all, you could have seven different
> >> elements named 'to' inside of seven different complex types.
> >>
> >>
> >>
> >> On Fri, Apr 10, 2009 at 5:22 PM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > Yes I just saw your commit and the file you uploaded is the full copy
> of
> >> > notes.xsd:
> >> > +<?xml version="1.0"?>
> >> > +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >> > +
> >> > +<xs:element name="note">
> >> > + <xs:complexType>
> >> > +   <xs:sequence>
> >> > +     <xs:element name="to" type="xs:string"/>
> >> > +     <xs:element name="from" type="xs:string"/>
> >> > +     <xs:element name="heading" type="xs:string"/>
> >> > +     <xs:element name="body" type="xs:string"/>
> >> > +   </xs:sequence>
> >> > + </xs:complexType>
> >> > +</xs:element>
> >> > +
> >> > +</xs:schema>
> >> >
> >> >
> >> > On Fri, Apr 10, 2009 at 10:18 PM, Benson Margulies <
> >> bimargulies@gmail.com>wrote:
> >> >
> >> >> I don't have a full copy of 'notes.xsd'. I just have the fragment
> from
> >> >> your first message. To give me a whole file, make a JIRA and attach
> >> >> it. I just committed my unit test: grab the source tree from svn and
> >> >> look at
> >> >>
> >> >> /XmlSchema/src/test/java/tests/SingleElementNoNamespace.java
> >> >>
> >> >> The svn path you want is
> >> >>
> >> >>
> >> >>
> >>
> http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <hossbert@gmail.com
> >
> >> >> wrote:
> >> >> > JDK is 6
> >> >> > Don't have anything special in my classpath:
> >> >> > .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
> >> >> > files\java\jdk1.6.0_10\lib
> >> >> >
> >> >> > I don't have maven so I can't make a self-contained failing case
> using
> >> >> > maven.
> >> >> >
> >> >> > Is one member not incorrect since note.xsd has 5 elements:
> >> >> >
> >> >> > note
> >> >> > to
> >> >> > from
> >> >> > heading
> >> >> > body
> >> >> >
> >> >> > Can you provide your code please?
> >> >> >
> >> >> > Thanks,
> >> >> > Patrick
> >> >> >
> >> >> > On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <
> >> >> bimargulies@gmail.com>wrote:
> >> >> >
> >> >> >> I just turned your code into a unit test, and it worked. The items
> >> >> >> collection comes up with one member, as does the elements object
> >> >> >> table.
> >> >> >>
> >> >> >> So, we have to look for some more interesting explanation. What
> JDK?
> >> >> >> Anything fancy in your class path, like a specific version of
> Xerces
> >> >> >> or some other alternative parser?
> >> >> >>
> >> >> >> Can you make a self-contained failing case using maven to specify
> all
> >> >> >> the dependencies?
> >> >> >>
> >> >> >> It is remotely possible that you've hit something fixed since
> 1.4.4,
> >> >> >> but very little has changed since then, and nothing in this
> >> >> >> neighborhood.
> >> >> >>
> >> >> >>
> >> >> >> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <
> hossbert@gmail.com
> >> >
> >> >> >> wrote:
> >> >> >> > I assumes that's:
> >> >> >> >
> >> >> >> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
> >> >> >> > System.out.println(elementsObjTbl.getCount());
> >> >> >> >
> >> >> >> > That's also empty.
> >> >> >> >
> >> >> >> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <
> >> >> bimargulies@gmail.com
> >> >> >> >wrote:
> >> >> >> >
> >> >> >> >> I would expect that code of yours to work. My only suggestion
> >> before
> >> >> I
> >> >> >> >> debug is that you get the element collection and see if THAT is
> >> also
> >> >> >> >> empty.
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <
> >> hossbert@gmail.com
> >> >> >
> >> >> >> >> wrote:
> >> >> >> >> > Cool, thanks :)
> >> >> >> >> > Is it a bug or?
> >> >> >> >> >
> >> >> >> >> > Maybe you could include some code showing the common uses of
> the
> >> >> API.
> >> >> >> >> >
> >> >> >> >> > I basically want to be able to extract the elements of a
> schema
> >> and
> >> >> >> then
> >> >> >> >> > display it using a
> >> >> >> >> > JTree.
> >> >> >> >> >
> >> >> >> >> > Patrick
> >> >> >> >> >
> >> >> >> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
> >> >> >> bimargulies@gmail.com
> >> >> >> >> >wrote:
> >> >> >> >> >
> >> >> >> >> >> I'm a bit buried under Passover, but I'll sort this out over
> >> the
> >> >> >> >> >> weekend some time.
> >> >> >> >> >>
> >> >> >> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
> >> >> >> hossbert@gmail.com>
> >> >> >> >> >> wrote:
> >> >> >> >> >> > Version 1.4.4
> >> >> >> >> >> >
> >> >> >> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
> >> >> >> >> bimargulies@gmail.com
> >> >> >> >> >> >wrote:
> >> >> >> >> >> >
> >> >> >> >> >> >> You don't have a target namespace.... but that should be
> OK.
> >> >> What
> >> >> >> >> >> >> version have you grabbed?
> >> >> >> >> >> >>
> >> >> >> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
> >> >> >> hossbert@gmail.com
> >> >> >> >> >
> >> >> >> >> >> >> wrote:
> >> >> >> >> >> >> > Hi,
> >> >> >> >> >> >> > Trying to start using the API. Following the
> instructions
> >> in
> >> >> the
> >> >> >> >> >> tutorial
> >> >> >> >> >> >> I
> >> >> >> >> >> >> > can get the schema to print fine.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > However now I would like to start accessing elements.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > I tried the following:
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > InputStream is = new FileInputStream("note.xsd");
> >> >> >> >> >> >> > XmlSchemaCollection schemaCol = new
> XmlSchemaCollection();
> >> >> >> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is),
> >> >> null);
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > XmlSchemaObjectTable objectTable =
> schema.getElements();
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > System.out.println(objectTable.getCount());
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > This prints out 0. Should it not print out the number
> of
> >> >> >> elements?
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > notes.xsd is as follows:
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > <?xml version="1.0"?>
> >> >> >> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema
> ">
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > <xs:element name="note">
> >> >> >> >> >> >> >  <xs:complexType>
> >> >> >> >> >> >> >    <xs:sequence>
> >> >> >> >> >> >> >      <xs:element name="to" type="xs:string"/>
> >> >> >> >> >> >> >      <xs:element name="from" type="xs:string"/>
> >> >> >> >> >> >> >      <xs:element name="heading" type="xs:string"/>
> >> >> >> >> >> >> >      <xs:element name="body" type="xs:string"/>
> >> >> >> >> >> >> >    </xs:sequence>
> >> >> >> >> >> >> >  </xs:complexType>
> >> >> >> >> >> >> > </xs:element>
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > </xs:schema>
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > Thanks,
> >> >> >> >> >> >> >
> >> >> >> >> >> >> > Patrick
> >> >> >> >> >> >> >
> >> >> >> >> >> >>
> >> >> >> >> >> >
> >> >> >> >> >>
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
Yes. GetResourceAsStream takes classpath names, not file system
pathnames. Stick with FileInputStream for those.

More in a minute ...


On Fri, Apr 10, 2009 at 5:31 PM, Patrick Kiernan <ho...@gmail.com> wrote:
> Ok fair enough. How do you access the elements in the sequence? ie. extract
> their names?
> I just tried your test case as a java class:
>
> package schemaparser;
>
> import java.io.InputStream;
>
> import javax.xml.transform.stream.StreamSource;
>
> import org.apache.ws.commons.schema.XmlSchema;
> import org.apache.ws.commons.schema.XmlSchemaCollection;
> import org.apache.ws.commons.schema.XmlSchemaObjectTable;
>
>
> public class XSDSchemaTest2  {
>
>       public static void main(String [] args){
>
>           try{
>               InputStream is =
>                       XSDSchemaTest2.class.
>
> getClassLoader().getResourceAsStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
>               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>               XmlSchema schema = schemaCol.read(new StreamSource(is),
> null);
>               XmlSchemaObjectTable objectTable = schema.getElements();
>               System.out.println(objectTable.getCount());
>           } catch(Exception ex){
>               ex.printStackTrace();
>           }
>
>       }
> }
>
> When I try and run that I get the following error:
>
> org.apache.ws.commons.schema.XmlSchemaException
>        at
> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:386)
>        at
> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:422)
>        at
> org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:448)
>        at schemaparser.XSDSchemaTest2.main(XSDSchemaTest2.java:23)
>
> Any idea what's wrong there?
>
> Thanks,
> Patrick
>
> On Fri, Apr 10, 2009 at 10:26 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> Oh! I completely misunderstood the question.
>>
>> Only top-level elements go into the collections. The elements inside a
>> sequence do not. So those elements are not supposed to be in items or
>> the elements object table. After all, you could have seven different
>> elements named 'to' inside of seven different complex types.
>>
>>
>>
>> On Fri, Apr 10, 2009 at 5:22 PM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Yes I just saw your commit and the file you uploaded is the full copy of
>> > notes.xsd:
>> > +<?xml version="1.0"?>
>> > +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> > +
>> > +<xs:element name="note">
>> > + <xs:complexType>
>> > +   <xs:sequence>
>> > +     <xs:element name="to" type="xs:string"/>
>> > +     <xs:element name="from" type="xs:string"/>
>> > +     <xs:element name="heading" type="xs:string"/>
>> > +     <xs:element name="body" type="xs:string"/>
>> > +   </xs:sequence>
>> > + </xs:complexType>
>> > +</xs:element>
>> > +
>> > +</xs:schema>
>> >
>> >
>> > On Fri, Apr 10, 2009 at 10:18 PM, Benson Margulies <
>> bimargulies@gmail.com>wrote:
>> >
>> >> I don't have a full copy of 'notes.xsd'. I just have the fragment from
>> >> your first message. To give me a whole file, make a JIRA and attach
>> >> it. I just committed my unit test: grab the source tree from svn and
>> >> look at
>> >>
>> >> /XmlSchema/src/test/java/tests/SingleElementNoNamespace.java
>> >>
>> >> The svn path you want is
>> >>
>> >>
>> >>
>> http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > JDK is 6
>> >> > Don't have anything special in my classpath:
>> >> > .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
>> >> > files\java\jdk1.6.0_10\lib
>> >> >
>> >> > I don't have maven so I can't make a self-contained failing case using
>> >> > maven.
>> >> >
>> >> > Is one member not incorrect since note.xsd has 5 elements:
>> >> >
>> >> > note
>> >> > to
>> >> > from
>> >> > heading
>> >> > body
>> >> >
>> >> > Can you provide your code please?
>> >> >
>> >> > Thanks,
>> >> > Patrick
>> >> >
>> >> > On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <
>> >> bimargulies@gmail.com>wrote:
>> >> >
>> >> >> I just turned your code into a unit test, and it worked. The items
>> >> >> collection comes up with one member, as does the elements object
>> >> >> table.
>> >> >>
>> >> >> So, we have to look for some more interesting explanation. What JDK?
>> >> >> Anything fancy in your class path, like a specific version of Xerces
>> >> >> or some other alternative parser?
>> >> >>
>> >> >> Can you make a self-contained failing case using maven to specify all
>> >> >> the dependencies?
>> >> >>
>> >> >> It is remotely possible that you've hit something fixed since 1.4.4,
>> >> >> but very little has changed since then, and nothing in this
>> >> >> neighborhood.
>> >> >>
>> >> >>
>> >> >> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <hossbert@gmail.com
>> >
>> >> >> wrote:
>> >> >> > I assumes that's:
>> >> >> >
>> >> >> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
>> >> >> > System.out.println(elementsObjTbl.getCount());
>> >> >> >
>> >> >> > That's also empty.
>> >> >> >
>> >> >> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <
>> >> bimargulies@gmail.com
>> >> >> >wrote:
>> >> >> >
>> >> >> >> I would expect that code of yours to work. My only suggestion
>> before
>> >> I
>> >> >> >> debug is that you get the element collection and see if THAT is
>> also
>> >> >> >> empty.
>> >> >> >>
>> >> >> >>
>> >> >> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <
>> hossbert@gmail.com
>> >> >
>> >> >> >> wrote:
>> >> >> >> > Cool, thanks :)
>> >> >> >> > Is it a bug or?
>> >> >> >> >
>> >> >> >> > Maybe you could include some code showing the common uses of the
>> >> API.
>> >> >> >> >
>> >> >> >> > I basically want to be able to extract the elements of a schema
>> and
>> >> >> then
>> >> >> >> > display it using a
>> >> >> >> > JTree.
>> >> >> >> >
>> >> >> >> > Patrick
>> >> >> >> >
>> >> >> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
>> >> >> bimargulies@gmail.com
>> >> >> >> >wrote:
>> >> >> >> >
>> >> >> >> >> I'm a bit buried under Passover, but I'll sort this out over
>> the
>> >> >> >> >> weekend some time.
>> >> >> >> >>
>> >> >> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
>> >> >> hossbert@gmail.com>
>> >> >> >> >> wrote:
>> >> >> >> >> > Version 1.4.4
>> >> >> >> >> >
>> >> >> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
>> >> >> >> bimargulies@gmail.com
>> >> >> >> >> >wrote:
>> >> >> >> >> >
>> >> >> >> >> >> You don't have a target namespace.... but that should be OK.
>> >> What
>> >> >> >> >> >> version have you grabbed?
>> >> >> >> >> >>
>> >> >> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
>> >> >> hossbert@gmail.com
>> >> >> >> >
>> >> >> >> >> >> wrote:
>> >> >> >> >> >> > Hi,
>> >> >> >> >> >> > Trying to start using the API. Following the instructions
>> in
>> >> the
>> >> >> >> >> tutorial
>> >> >> >> >> >> I
>> >> >> >> >> >> > can get the schema to print fine.
>> >> >> >> >> >> >
>> >> >> >> >> >> > However now I would like to start accessing elements.
>> >> >> >> >> >> >
>> >> >> >> >> >> > I tried the following:
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > InputStream is = new FileInputStream("note.xsd");
>> >> >> >> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >> >> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is),
>> >> null);
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >> >> >> >> >
>> >> >> >> >> >> > System.out.println(objectTable.getCount());
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > This prints out 0. Should it not print out the number of
>> >> >> elements?
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > notes.xsd is as follows:
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > <?xml version="1.0"?>
>> >> >> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> >> >> >> >> >
>> >> >> >> >> >> > <xs:element name="note">
>> >> >> >> >> >> >  <xs:complexType>
>> >> >> >> >> >> >    <xs:sequence>
>> >> >> >> >> >> >      <xs:element name="to" type="xs:string"/>
>> >> >> >> >> >> >      <xs:element name="from" type="xs:string"/>
>> >> >> >> >> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >> >> >> >> >      <xs:element name="body" type="xs:string"/>
>> >> >> >> >> >> >    </xs:sequence>
>> >> >> >> >> >> >  </xs:complexType>
>> >> >> >> >> >> > </xs:element>
>> >> >> >> >> >> >
>> >> >> >> >> >> > </xs:schema>
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > Thanks,
>> >> >> >> >> >> >
>> >> >> >> >> >> > Patrick
>> >> >> >> >> >> >
>> >> >> >> >> >>
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Ok fair enough. How do you access the elements in the sequence? ie. extract
their names?
I just tried your test case as a java class:

package schemaparser;

import java.io.InputStream;

import javax.xml.transform.stream.StreamSource;

import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaObjectTable;


public class XSDSchemaTest2  {

       public static void main(String [] args){

           try{
               InputStream is =
                       XSDSchemaTest2.class.

getClassLoader().getResourceAsStream("C:\\Users\\Patrick\\Documents\\college\\FYP\\xml\\note.xsd");
               XmlSchemaCollection schemaCol = new XmlSchemaCollection();
               XmlSchema schema = schemaCol.read(new StreamSource(is),
null);
               XmlSchemaObjectTable objectTable = schema.getElements();
               System.out.println(objectTable.getCount());
           } catch(Exception ex){
               ex.printStackTrace();
           }

       }
}

When I try and run that I get the following error:

org.apache.ws.commons.schema.XmlSchemaException
        at
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:386)
        at
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:422)
        at
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:448)
        at schemaparser.XSDSchemaTest2.main(XSDSchemaTest2.java:23)

Any idea what's wrong there?

Thanks,
Patrick

On Fri, Apr 10, 2009 at 10:26 PM, Benson Margulies <bi...@gmail.com>wrote:

> Oh! I completely misunderstood the question.
>
> Only top-level elements go into the collections. The elements inside a
> sequence do not. So those elements are not supposed to be in items or
> the elements object table. After all, you could have seven different
> elements named 'to' inside of seven different complex types.
>
>
>
> On Fri, Apr 10, 2009 at 5:22 PM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > Yes I just saw your commit and the file you uploaded is the full copy of
> > notes.xsd:
> > +<?xml version="1.0"?>
> > +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> > +
> > +<xs:element name="note">
> > + <xs:complexType>
> > +   <xs:sequence>
> > +     <xs:element name="to" type="xs:string"/>
> > +     <xs:element name="from" type="xs:string"/>
> > +     <xs:element name="heading" type="xs:string"/>
> > +     <xs:element name="body" type="xs:string"/>
> > +   </xs:sequence>
> > + </xs:complexType>
> > +</xs:element>
> > +
> > +</xs:schema>
> >
> >
> > On Fri, Apr 10, 2009 at 10:18 PM, Benson Margulies <
> bimargulies@gmail.com>wrote:
> >
> >> I don't have a full copy of 'notes.xsd'. I just have the fragment from
> >> your first message. To give me a whole file, make a JIRA and attach
> >> it. I just committed my unit test: grab the source tree from svn and
> >> look at
> >>
> >> /XmlSchema/src/test/java/tests/SingleElementNoNamespace.java
> >>
> >> The svn path you want is
> >>
> >>
> >>
> http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH
> >>
> >>
> >>
> >>
> >>
> >> On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > JDK is 6
> >> > Don't have anything special in my classpath:
> >> > .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
> >> > files\java\jdk1.6.0_10\lib
> >> >
> >> > I don't have maven so I can't make a self-contained failing case using
> >> > maven.
> >> >
> >> > Is one member not incorrect since note.xsd has 5 elements:
> >> >
> >> > note
> >> > to
> >> > from
> >> > heading
> >> > body
> >> >
> >> > Can you provide your code please?
> >> >
> >> > Thanks,
> >> > Patrick
> >> >
> >> > On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <
> >> bimargulies@gmail.com>wrote:
> >> >
> >> >> I just turned your code into a unit test, and it worked. The items
> >> >> collection comes up with one member, as does the elements object
> >> >> table.
> >> >>
> >> >> So, we have to look for some more interesting explanation. What JDK?
> >> >> Anything fancy in your class path, like a specific version of Xerces
> >> >> or some other alternative parser?
> >> >>
> >> >> Can you make a self-contained failing case using maven to specify all
> >> >> the dependencies?
> >> >>
> >> >> It is remotely possible that you've hit something fixed since 1.4.4,
> >> >> but very little has changed since then, and nothing in this
> >> >> neighborhood.
> >> >>
> >> >>
> >> >> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <hossbert@gmail.com
> >
> >> >> wrote:
> >> >> > I assumes that's:
> >> >> >
> >> >> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
> >> >> > System.out.println(elementsObjTbl.getCount());
> >> >> >
> >> >> > That's also empty.
> >> >> >
> >> >> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <
> >> bimargulies@gmail.com
> >> >> >wrote:
> >> >> >
> >> >> >> I would expect that code of yours to work. My only suggestion
> before
> >> I
> >> >> >> debug is that you get the element collection and see if THAT is
> also
> >> >> >> empty.
> >> >> >>
> >> >> >>
> >> >> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <
> hossbert@gmail.com
> >> >
> >> >> >> wrote:
> >> >> >> > Cool, thanks :)
> >> >> >> > Is it a bug or?
> >> >> >> >
> >> >> >> > Maybe you could include some code showing the common uses of the
> >> API.
> >> >> >> >
> >> >> >> > I basically want to be able to extract the elements of a schema
> and
> >> >> then
> >> >> >> > display it using a
> >> >> >> > JTree.
> >> >> >> >
> >> >> >> > Patrick
> >> >> >> >
> >> >> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
> >> >> bimargulies@gmail.com
> >> >> >> >wrote:
> >> >> >> >
> >> >> >> >> I'm a bit buried under Passover, but I'll sort this out over
> the
> >> >> >> >> weekend some time.
> >> >> >> >>
> >> >> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
> >> >> hossbert@gmail.com>
> >> >> >> >> wrote:
> >> >> >> >> > Version 1.4.4
> >> >> >> >> >
> >> >> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
> >> >> >> bimargulies@gmail.com
> >> >> >> >> >wrote:
> >> >> >> >> >
> >> >> >> >> >> You don't have a target namespace.... but that should be OK.
> >> What
> >> >> >> >> >> version have you grabbed?
> >> >> >> >> >>
> >> >> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
> >> >> hossbert@gmail.com
> >> >> >> >
> >> >> >> >> >> wrote:
> >> >> >> >> >> > Hi,
> >> >> >> >> >> > Trying to start using the API. Following the instructions
> in
> >> the
> >> >> >> >> tutorial
> >> >> >> >> >> I
> >> >> >> >> >> > can get the schema to print fine.
> >> >> >> >> >> >
> >> >> >> >> >> > However now I would like to start accessing elements.
> >> >> >> >> >> >
> >> >> >> >> >> > I tried the following:
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > InputStream is = new FileInputStream("note.xsd");
> >> >> >> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >> >> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is),
> >> null);
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
> >> >> >> >> >> >
> >> >> >> >> >> > System.out.println(objectTable.getCount());
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > This prints out 0. Should it not print out the number of
> >> >> elements?
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > notes.xsd is as follows:
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > <?xml version="1.0"?>
> >> >> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >> >> >> >> >> >
> >> >> >> >> >> > <xs:element name="note">
> >> >> >> >> >> >  <xs:complexType>
> >> >> >> >> >> >    <xs:sequence>
> >> >> >> >> >> >      <xs:element name="to" type="xs:string"/>
> >> >> >> >> >> >      <xs:element name="from" type="xs:string"/>
> >> >> >> >> >> >      <xs:element name="heading" type="xs:string"/>
> >> >> >> >> >> >      <xs:element name="body" type="xs:string"/>
> >> >> >> >> >> >    </xs:sequence>
> >> >> >> >> >> >  </xs:complexType>
> >> >> >> >> >> > </xs:element>
> >> >> >> >> >> >
> >> >> >> >> >> > </xs:schema>
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> >
> >> >> >> >> >> > Thanks,
> >> >> >> >> >> >
> >> >> >> >> >> > Patrick
> >> >> >> >> >> >
> >> >> >> >> >>
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
Oh! I completely misunderstood the question.

Only top-level elements go into the collections. The elements inside a
sequence do not. So those elements are not supposed to be in items or
the elements object table. After all, you could have seven different
elements named 'to' inside of seven different complex types.



On Fri, Apr 10, 2009 at 5:22 PM, Patrick Kiernan <ho...@gmail.com> wrote:
> Yes I just saw your commit and the file you uploaded is the full copy of
> notes.xsd:
> +<?xml version="1.0"?>
> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> +
> +<xs:element name="note">
> + <xs:complexType>
> +   <xs:sequence>
> +     <xs:element name="to" type="xs:string"/>
> +     <xs:element name="from" type="xs:string"/>
> +     <xs:element name="heading" type="xs:string"/>
> +     <xs:element name="body" type="xs:string"/>
> +   </xs:sequence>
> + </xs:complexType>
> +</xs:element>
> +
> +</xs:schema>
>
>
> On Fri, Apr 10, 2009 at 10:18 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> I don't have a full copy of 'notes.xsd'. I just have the fragment from
>> your first message. To give me a whole file, make a JIRA and attach
>> it. I just committed my unit test: grab the source tree from svn and
>> look at
>>
>> /XmlSchema/src/test/java/tests/SingleElementNoNamespace.java
>>
>> The svn path you want is
>>
>>
>> http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH
>>
>>
>>
>>
>>
>> On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > JDK is 6
>> > Don't have anything special in my classpath:
>> > .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
>> > files\java\jdk1.6.0_10\lib
>> >
>> > I don't have maven so I can't make a self-contained failing case using
>> > maven.
>> >
>> > Is one member not incorrect since note.xsd has 5 elements:
>> >
>> > note
>> > to
>> > from
>> > heading
>> > body
>> >
>> > Can you provide your code please?
>> >
>> > Thanks,
>> > Patrick
>> >
>> > On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <
>> bimargulies@gmail.com>wrote:
>> >
>> >> I just turned your code into a unit test, and it worked. The items
>> >> collection comes up with one member, as does the elements object
>> >> table.
>> >>
>> >> So, we have to look for some more interesting explanation. What JDK?
>> >> Anything fancy in your class path, like a specific version of Xerces
>> >> or some other alternative parser?
>> >>
>> >> Can you make a self-contained failing case using maven to specify all
>> >> the dependencies?
>> >>
>> >> It is remotely possible that you've hit something fixed since 1.4.4,
>> >> but very little has changed since then, and nothing in this
>> >> neighborhood.
>> >>
>> >>
>> >> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > I assumes that's:
>> >> >
>> >> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
>> >> > System.out.println(elementsObjTbl.getCount());
>> >> >
>> >> > That's also empty.
>> >> >
>> >> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <
>> bimargulies@gmail.com
>> >> >wrote:
>> >> >
>> >> >> I would expect that code of yours to work. My only suggestion before
>> I
>> >> >> debug is that you get the element collection and see if THAT is also
>> >> >> empty.
>> >> >>
>> >> >>
>> >> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <hossbert@gmail.com
>> >
>> >> >> wrote:
>> >> >> > Cool, thanks :)
>> >> >> > Is it a bug or?
>> >> >> >
>> >> >> > Maybe you could include some code showing the common uses of the
>> API.
>> >> >> >
>> >> >> > I basically want to be able to extract the elements of a schema and
>> >> then
>> >> >> > display it using a
>> >> >> > JTree.
>> >> >> >
>> >> >> > Patrick
>> >> >> >
>> >> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
>> >> bimargulies@gmail.com
>> >> >> >wrote:
>> >> >> >
>> >> >> >> I'm a bit buried under Passover, but I'll sort this out over the
>> >> >> >> weekend some time.
>> >> >> >>
>> >> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
>> >> hossbert@gmail.com>
>> >> >> >> wrote:
>> >> >> >> > Version 1.4.4
>> >> >> >> >
>> >> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
>> >> >> bimargulies@gmail.com
>> >> >> >> >wrote:
>> >> >> >> >
>> >> >> >> >> You don't have a target namespace.... but that should be OK.
>> What
>> >> >> >> >> version have you grabbed?
>> >> >> >> >>
>> >> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
>> >> hossbert@gmail.com
>> >> >> >
>> >> >> >> >> wrote:
>> >> >> >> >> > Hi,
>> >> >> >> >> > Trying to start using the API. Following the instructions in
>> the
>> >> >> >> tutorial
>> >> >> >> >> I
>> >> >> >> >> > can get the schema to print fine.
>> >> >> >> >> >
>> >> >> >> >> > However now I would like to start accessing elements.
>> >> >> >> >> >
>> >> >> >> >> > I tried the following:
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > InputStream is = new FileInputStream("note.xsd");
>> >> >> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is),
>> null);
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >> >> >> >
>> >> >> >> >> > System.out.println(objectTable.getCount());
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > This prints out 0. Should it not print out the number of
>> >> elements?
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > notes.xsd is as follows:
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > <?xml version="1.0"?>
>> >> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> >> >> >> >
>> >> >> >> >> > <xs:element name="note">
>> >> >> >> >> >  <xs:complexType>
>> >> >> >> >> >    <xs:sequence>
>> >> >> >> >> >      <xs:element name="to" type="xs:string"/>
>> >> >> >> >> >      <xs:element name="from" type="xs:string"/>
>> >> >> >> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >> >> >> >      <xs:element name="body" type="xs:string"/>
>> >> >> >> >> >    </xs:sequence>
>> >> >> >> >> >  </xs:complexType>
>> >> >> >> >> > </xs:element>
>> >> >> >> >> >
>> >> >> >> >> > </xs:schema>
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > Thanks,
>> >> >> >> >> >
>> >> >> >> >> > Patrick
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Yes I just saw your commit and the file you uploaded is the full copy of
notes.xsd:
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+<xs:element name="note">
+ <xs:complexType>
+   <xs:sequence>
+     <xs:element name="to" type="xs:string"/>
+     <xs:element name="from" type="xs:string"/>
+     <xs:element name="heading" type="xs:string"/>
+     <xs:element name="body" type="xs:string"/>
+   </xs:sequence>
+ </xs:complexType>
+</xs:element>
+
+</xs:schema>


On Fri, Apr 10, 2009 at 10:18 PM, Benson Margulies <bi...@gmail.com>wrote:

> I don't have a full copy of 'notes.xsd'. I just have the fragment from
> your first message. To give me a whole file, make a JIRA and attach
> it. I just committed my unit test: grab the source tree from svn and
> look at
>
> /XmlSchema/src/test/java/tests/SingleElementNoNamespace.java
>
> The svn path you want is
>
>
> http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH
>
>
>
>
>
> On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > JDK is 6
> > Don't have anything special in my classpath:
> > .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
> > files\java\jdk1.6.0_10\lib
> >
> > I don't have maven so I can't make a self-contained failing case using
> > maven.
> >
> > Is one member not incorrect since note.xsd has 5 elements:
> >
> > note
> > to
> > from
> > heading
> > body
> >
> > Can you provide your code please?
> >
> > Thanks,
> > Patrick
> >
> > On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <
> bimargulies@gmail.com>wrote:
> >
> >> I just turned your code into a unit test, and it worked. The items
> >> collection comes up with one member, as does the elements object
> >> table.
> >>
> >> So, we have to look for some more interesting explanation. What JDK?
> >> Anything fancy in your class path, like a specific version of Xerces
> >> or some other alternative parser?
> >>
> >> Can you make a self-contained failing case using maven to specify all
> >> the dependencies?
> >>
> >> It is remotely possible that you've hit something fixed since 1.4.4,
> >> but very little has changed since then, and nothing in this
> >> neighborhood.
> >>
> >>
> >> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > I assumes that's:
> >> >
> >> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
> >> > System.out.println(elementsObjTbl.getCount());
> >> >
> >> > That's also empty.
> >> >
> >> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <
> bimargulies@gmail.com
> >> >wrote:
> >> >
> >> >> I would expect that code of yours to work. My only suggestion before
> I
> >> >> debug is that you get the element collection and see if THAT is also
> >> >> empty.
> >> >>
> >> >>
> >> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <hossbert@gmail.com
> >
> >> >> wrote:
> >> >> > Cool, thanks :)
> >> >> > Is it a bug or?
> >> >> >
> >> >> > Maybe you could include some code showing the common uses of the
> API.
> >> >> >
> >> >> > I basically want to be able to extract the elements of a schema and
> >> then
> >> >> > display it using a
> >> >> > JTree.
> >> >> >
> >> >> > Patrick
> >> >> >
> >> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
> >> bimargulies@gmail.com
> >> >> >wrote:
> >> >> >
> >> >> >> I'm a bit buried under Passover, but I'll sort this out over the
> >> >> >> weekend some time.
> >> >> >>
> >> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
> >> hossbert@gmail.com>
> >> >> >> wrote:
> >> >> >> > Version 1.4.4
> >> >> >> >
> >> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
> >> >> bimargulies@gmail.com
> >> >> >> >wrote:
> >> >> >> >
> >> >> >> >> You don't have a target namespace.... but that should be OK.
> What
> >> >> >> >> version have you grabbed?
> >> >> >> >>
> >> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
> >> hossbert@gmail.com
> >> >> >
> >> >> >> >> wrote:
> >> >> >> >> > Hi,
> >> >> >> >> > Trying to start using the API. Following the instructions in
> the
> >> >> >> tutorial
> >> >> >> >> I
> >> >> >> >> > can get the schema to print fine.
> >> >> >> >> >
> >> >> >> >> > However now I would like to start accessing elements.
> >> >> >> >> >
> >> >> >> >> > I tried the following:
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > InputStream is = new FileInputStream("note.xsd");
> >> >> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is),
> null);
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
> >> >> >> >> >
> >> >> >> >> > System.out.println(objectTable.getCount());
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > This prints out 0. Should it not print out the number of
> >> elements?
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > notes.xsd is as follows:
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > <?xml version="1.0"?>
> >> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >> >> >> >> >
> >> >> >> >> > <xs:element name="note">
> >> >> >> >> >  <xs:complexType>
> >> >> >> >> >    <xs:sequence>
> >> >> >> >> >      <xs:element name="to" type="xs:string"/>
> >> >> >> >> >      <xs:element name="from" type="xs:string"/>
> >> >> >> >> >      <xs:element name="heading" type="xs:string"/>
> >> >> >> >> >      <xs:element name="body" type="xs:string"/>
> >> >> >> >> >    </xs:sequence>
> >> >> >> >> >  </xs:complexType>
> >> >> >> >> > </xs:element>
> >> >> >> >> >
> >> >> >> >> > </xs:schema>
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > Thanks,
> >> >> >> >> >
> >> >> >> >> > Patrick
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
I don't have a full copy of 'notes.xsd'. I just have the fragment from
your first message. To give me a whole file, make a JIRA and attach
it. I just committed my unit test: grab the source tree from svn and
look at

/XmlSchema/src/test/java/tests/SingleElementNoNamespace.java

The svn path you want is

http://svn.apache.org/repos/asf/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH





On Fri, Apr 10, 2009 at 5:12 PM, Patrick Kiernan <ho...@gmail.com> wrote:
> JDK is 6
> Don't have anything special in my classpath:
> .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
> files\java\jdk1.6.0_10\lib
>
> I don't have maven so I can't make a self-contained failing case using
> maven.
>
> Is one member not incorrect since note.xsd has 5 elements:
>
> note
> to
> from
> heading
> body
>
> Can you provide your code please?
>
> Thanks,
> Patrick
>
> On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> I just turned your code into a unit test, and it worked. The items
>> collection comes up with one member, as does the elements object
>> table.
>>
>> So, we have to look for some more interesting explanation. What JDK?
>> Anything fancy in your class path, like a specific version of Xerces
>> or some other alternative parser?
>>
>> Can you make a self-contained failing case using maven to specify all
>> the dependencies?
>>
>> It is remotely possible that you've hit something fixed since 1.4.4,
>> but very little has changed since then, and nothing in this
>> neighborhood.
>>
>>
>> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > I assumes that's:
>> >
>> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
>> > System.out.println(elementsObjTbl.getCount());
>> >
>> > That's also empty.
>> >
>> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <bimargulies@gmail.com
>> >wrote:
>> >
>> >> I would expect that code of yours to work. My only suggestion before I
>> >> debug is that you get the element collection and see if THAT is also
>> >> empty.
>> >>
>> >>
>> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > Cool, thanks :)
>> >> > Is it a bug or?
>> >> >
>> >> > Maybe you could include some code showing the common uses of the API.
>> >> >
>> >> > I basically want to be able to extract the elements of a schema and
>> then
>> >> > display it using a
>> >> > JTree.
>> >> >
>> >> > Patrick
>> >> >
>> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
>> bimargulies@gmail.com
>> >> >wrote:
>> >> >
>> >> >> I'm a bit buried under Passover, but I'll sort this out over the
>> >> >> weekend some time.
>> >> >>
>> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
>> hossbert@gmail.com>
>> >> >> wrote:
>> >> >> > Version 1.4.4
>> >> >> >
>> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
>> >> bimargulies@gmail.com
>> >> >> >wrote:
>> >> >> >
>> >> >> >> You don't have a target namespace.... but that should be OK. What
>> >> >> >> version have you grabbed?
>> >> >> >>
>> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
>> hossbert@gmail.com
>> >> >
>> >> >> >> wrote:
>> >> >> >> > Hi,
>> >> >> >> > Trying to start using the API. Following the instructions in the
>> >> >> tutorial
>> >> >> >> I
>> >> >> >> > can get the schema to print fine.
>> >> >> >> >
>> >> >> >> > However now I would like to start accessing elements.
>> >> >> >> >
>> >> >> >> > I tried the following:
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > InputStream is = new FileInputStream("note.xsd");
>> >> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >> >> >
>> >> >> >> > System.out.println(objectTable.getCount());
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > This prints out 0. Should it not print out the number of
>> elements?
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > notes.xsd is as follows:
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > <?xml version="1.0"?>
>> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> >> >> >
>> >> >> >> > <xs:element name="note">
>> >> >> >> >  <xs:complexType>
>> >> >> >> >    <xs:sequence>
>> >> >> >> >      <xs:element name="to" type="xs:string"/>
>> >> >> >> >      <xs:element name="from" type="xs:string"/>
>> >> >> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >> >> >      <xs:element name="body" type="xs:string"/>
>> >> >> >> >    </xs:sequence>
>> >> >> >> >  </xs:complexType>
>> >> >> >> > </xs:element>
>> >> >> >> >
>> >> >> >> > </xs:schema>
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > Thanks,
>> >> >> >> >
>> >> >> >> > Patrick
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
JDK is 6
Don't have anything special in my classpath:
.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\program
files\java\jdk1.6.0_10\lib

I don't have maven so I can't make a self-contained failing case using
maven.

Is one member not incorrect since note.xsd has 5 elements:

note
to
from
heading
body

Can you provide your code please?

Thanks,
Patrick

On Fri, Apr 10, 2009 at 10:02 PM, Benson Margulies <bi...@gmail.com>wrote:

> I just turned your code into a unit test, and it worked. The items
> collection comes up with one member, as does the elements object
> table.
>
> So, we have to look for some more interesting explanation. What JDK?
> Anything fancy in your class path, like a specific version of Xerces
> or some other alternative parser?
>
> Can you make a self-contained failing case using maven to specify all
> the dependencies?
>
> It is remotely possible that you've hit something fixed since 1.4.4,
> but very little has changed since then, and nothing in this
> neighborhood.
>
>
> On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > I assumes that's:
> >
> > XmlSchemaObjectTable elementsObjTbl = schema.getElements();
> > System.out.println(elementsObjTbl.getCount());
> >
> > That's also empty.
> >
> > On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <bimargulies@gmail.com
> >wrote:
> >
> >> I would expect that code of yours to work. My only suggestion before I
> >> debug is that you get the element collection and see if THAT is also
> >> empty.
> >>
> >>
> >> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > Cool, thanks :)
> >> > Is it a bug or?
> >> >
> >> > Maybe you could include some code showing the common uses of the API.
> >> >
> >> > I basically want to be able to extract the elements of a schema and
> then
> >> > display it using a
> >> > JTree.
> >> >
> >> > Patrick
> >> >
> >> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <
> bimargulies@gmail.com
> >> >wrote:
> >> >
> >> >> I'm a bit buried under Passover, but I'll sort this out over the
> >> >> weekend some time.
> >> >>
> >> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <
> hossbert@gmail.com>
> >> >> wrote:
> >> >> > Version 1.4.4
> >> >> >
> >> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
> >> bimargulies@gmail.com
> >> >> >wrote:
> >> >> >
> >> >> >> You don't have a target namespace.... but that should be OK. What
> >> >> >> version have you grabbed?
> >> >> >>
> >> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <
> hossbert@gmail.com
> >> >
> >> >> >> wrote:
> >> >> >> > Hi,
> >> >> >> > Trying to start using the API. Following the instructions in the
> >> >> tutorial
> >> >> >> I
> >> >> >> > can get the schema to print fine.
> >> >> >> >
> >> >> >> > However now I would like to start accessing elements.
> >> >> >> >
> >> >> >> > I tried the following:
> >> >> >> >
> >> >> >> >
> >> >> >> > InputStream is = new FileInputStream("note.xsd");
> >> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
> >> >> >> >
> >> >> >> >
> >> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
> >> >> >> >
> >> >> >> > System.out.println(objectTable.getCount());
> >> >> >> >
> >> >> >> >
> >> >> >> > This prints out 0. Should it not print out the number of
> elements?
> >> >> >> >
> >> >> >> >
> >> >> >> > notes.xsd is as follows:
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > <?xml version="1.0"?>
> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >> >> >> >
> >> >> >> > <xs:element name="note">
> >> >> >> >  <xs:complexType>
> >> >> >> >    <xs:sequence>
> >> >> >> >      <xs:element name="to" type="xs:string"/>
> >> >> >> >      <xs:element name="from" type="xs:string"/>
> >> >> >> >      <xs:element name="heading" type="xs:string"/>
> >> >> >> >      <xs:element name="body" type="xs:string"/>
> >> >> >> >    </xs:sequence>
> >> >> >> >  </xs:complexType>
> >> >> >> > </xs:element>
> >> >> >> >
> >> >> >> > </xs:schema>
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > Thanks,
> >> >> >> >
> >> >> >> > Patrick
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
I just turned your code into a unit test, and it worked. The items
collection comes up with one member, as does the elements object
table.

So, we have to look for some more interesting explanation. What JDK?
Anything fancy in your class path, like a specific version of Xerces
or some other alternative parser?

Can you make a self-contained failing case using maven to specify all
the dependencies?

It is remotely possible that you've hit something fixed since 1.4.4,
but very little has changed since then, and nothing in this
neighborhood.


On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <ho...@gmail.com> wrote:
> I assumes that's:
>
> XmlSchemaObjectTable elementsObjTbl = schema.getElements();
> System.out.println(elementsObjTbl.getCount());
>
> That's also empty.
>
> On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> I would expect that code of yours to work. My only suggestion before I
>> debug is that you get the element collection and see if THAT is also
>> empty.
>>
>>
>> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Cool, thanks :)
>> > Is it a bug or?
>> >
>> > Maybe you could include some code showing the common uses of the API.
>> >
>> > I basically want to be able to extract the elements of a schema and then
>> > display it using a
>> > JTree.
>> >
>> > Patrick
>> >
>> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <bimargulies@gmail.com
>> >wrote:
>> >
>> >> I'm a bit buried under Passover, but I'll sort this out over the
>> >> weekend some time.
>> >>
>> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > Version 1.4.4
>> >> >
>> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
>> bimargulies@gmail.com
>> >> >wrote:
>> >> >
>> >> >> You don't have a target namespace.... but that should be OK. What
>> >> >> version have you grabbed?
>> >> >>
>> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <hossbert@gmail.com
>> >
>> >> >> wrote:
>> >> >> > Hi,
>> >> >> > Trying to start using the API. Following the instructions in the
>> >> tutorial
>> >> >> I
>> >> >> > can get the schema to print fine.
>> >> >> >
>> >> >> > However now I would like to start accessing elements.
>> >> >> >
>> >> >> > I tried the following:
>> >> >> >
>> >> >> >
>> >> >> > InputStream is = new FileInputStream("note.xsd");
>> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
>> >> >> >
>> >> >> >
>> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >> >
>> >> >> > System.out.println(objectTable.getCount());
>> >> >> >
>> >> >> >
>> >> >> > This prints out 0. Should it not print out the number of elements?
>> >> >> >
>> >> >> >
>> >> >> > notes.xsd is as follows:
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > <?xml version="1.0"?>
>> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> >> >
>> >> >> > <xs:element name="note">
>> >> >> >  <xs:complexType>
>> >> >> >    <xs:sequence>
>> >> >> >      <xs:element name="to" type="xs:string"/>
>> >> >> >      <xs:element name="from" type="xs:string"/>
>> >> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >> >      <xs:element name="body" type="xs:string"/>
>> >> >> >    </xs:sequence>
>> >> >> >  </xs:complexType>
>> >> >> > </xs:element>
>> >> >> >
>> >> >> > </xs:schema>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > Thanks,
>> >> >> >
>> >> >> > Patrick
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
OK, I'll debug. This is most peculiar.

On Fri, Apr 10, 2009 at 4:38 PM, Patrick Kiernan <ho...@gmail.com> wrote:
> I assumes that's:
>
> XmlSchemaObjectTable elementsObjTbl = schema.getElements();
> System.out.println(elementsObjTbl.getCount());
>
> That's also empty.
>
> On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> I would expect that code of yours to work. My only suggestion before I
>> debug is that you get the element collection and see if THAT is also
>> empty.
>>
>>
>> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Cool, thanks :)
>> > Is it a bug or?
>> >
>> > Maybe you could include some code showing the common uses of the API.
>> >
>> > I basically want to be able to extract the elements of a schema and then
>> > display it using a
>> > JTree.
>> >
>> > Patrick
>> >
>> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <bimargulies@gmail.com
>> >wrote:
>> >
>> >> I'm a bit buried under Passover, but I'll sort this out over the
>> >> weekend some time.
>> >>
>> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > Version 1.4.4
>> >> >
>> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
>> bimargulies@gmail.com
>> >> >wrote:
>> >> >
>> >> >> You don't have a target namespace.... but that should be OK. What
>> >> >> version have you grabbed?
>> >> >>
>> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <hossbert@gmail.com
>> >
>> >> >> wrote:
>> >> >> > Hi,
>> >> >> > Trying to start using the API. Following the instructions in the
>> >> tutorial
>> >> >> I
>> >> >> > can get the schema to print fine.
>> >> >> >
>> >> >> > However now I would like to start accessing elements.
>> >> >> >
>> >> >> > I tried the following:
>> >> >> >
>> >> >> >
>> >> >> > InputStream is = new FileInputStream("note.xsd");
>> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
>> >> >> >
>> >> >> >
>> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >> >
>> >> >> > System.out.println(objectTable.getCount());
>> >> >> >
>> >> >> >
>> >> >> > This prints out 0. Should it not print out the number of elements?
>> >> >> >
>> >> >> >
>> >> >> > notes.xsd is as follows:
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > <?xml version="1.0"?>
>> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> >> >
>> >> >> > <xs:element name="note">
>> >> >> >  <xs:complexType>
>> >> >> >    <xs:sequence>
>> >> >> >      <xs:element name="to" type="xs:string"/>
>> >> >> >      <xs:element name="from" type="xs:string"/>
>> >> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >> >      <xs:element name="body" type="xs:string"/>
>> >> >> >    </xs:sequence>
>> >> >> >  </xs:complexType>
>> >> >> > </xs:element>
>> >> >> >
>> >> >> > </xs:schema>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > Thanks,
>> >> >> >
>> >> >> > Patrick
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
I assumes that's:

XmlSchemaObjectTable elementsObjTbl = schema.getElements();
System.out.println(elementsObjTbl.getCount());

That's also empty.

On Fri, Apr 10, 2009 at 9:27 PM, Benson Margulies <bi...@gmail.com>wrote:

> I would expect that code of yours to work. My only suggestion before I
> debug is that you get the element collection and see if THAT is also
> empty.
>
>
> On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > Cool, thanks :)
> > Is it a bug or?
> >
> > Maybe you could include some code showing the common uses of the API.
> >
> > I basically want to be able to extract the elements of a schema and then
> > display it using a
> > JTree.
> >
> > Patrick
> >
> > On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <bimargulies@gmail.com
> >wrote:
> >
> >> I'm a bit buried under Passover, but I'll sort this out over the
> >> weekend some time.
> >>
> >> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > Version 1.4.4
> >> >
> >> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <
> bimargulies@gmail.com
> >> >wrote:
> >> >
> >> >> You don't have a target namespace.... but that should be OK. What
> >> >> version have you grabbed?
> >> >>
> >> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <hossbert@gmail.com
> >
> >> >> wrote:
> >> >> > Hi,
> >> >> > Trying to start using the API. Following the instructions in the
> >> tutorial
> >> >> I
> >> >> > can get the schema to print fine.
> >> >> >
> >> >> > However now I would like to start accessing elements.
> >> >> >
> >> >> > I tried the following:
> >> >> >
> >> >> >
> >> >> > InputStream is = new FileInputStream("note.xsd");
> >> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
> >> >> >
> >> >> >
> >> >> > XmlSchemaObjectTable objectTable = schema.getElements();
> >> >> >
> >> >> > System.out.println(objectTable.getCount());
> >> >> >
> >> >> >
> >> >> > This prints out 0. Should it not print out the number of elements?
> >> >> >
> >> >> >
> >> >> > notes.xsd is as follows:
> >> >> >
> >> >> >
> >> >> >
> >> >> > <?xml version="1.0"?>
> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >> >> >
> >> >> > <xs:element name="note">
> >> >> >  <xs:complexType>
> >> >> >    <xs:sequence>
> >> >> >      <xs:element name="to" type="xs:string"/>
> >> >> >      <xs:element name="from" type="xs:string"/>
> >> >> >      <xs:element name="heading" type="xs:string"/>
> >> >> >      <xs:element name="body" type="xs:string"/>
> >> >> >    </xs:sequence>
> >> >> >  </xs:complexType>
> >> >> > </xs:element>
> >> >> >
> >> >> > </xs:schema>
> >> >> >
> >> >> >
> >> >> >
> >> >> > Thanks,
> >> >> >
> >> >> > Patrick
> >> >> >
> >> >>
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
I would expect that code of yours to work. My only suggestion before I
debug is that you get the element collection and see if THAT is also
empty.


On Fri, Apr 10, 2009 at 2:50 PM, Patrick Kiernan <ho...@gmail.com> wrote:
> Cool, thanks :)
> Is it a bug or?
>
> Maybe you could include some code showing the common uses of the API.
>
> I basically want to be able to extract the elements of a schema and then
> display it using a
> JTree.
>
> Patrick
>
> On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> I'm a bit buried under Passover, but I'll sort this out over the
>> weekend some time.
>>
>> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Version 1.4.4
>> >
>> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <bimargulies@gmail.com
>> >wrote:
>> >
>> >> You don't have a target namespace.... but that should be OK. What
>> >> version have you grabbed?
>> >>
>> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <ho...@gmail.com>
>> >> wrote:
>> >> > Hi,
>> >> > Trying to start using the API. Following the instructions in the
>> tutorial
>> >> I
>> >> > can get the schema to print fine.
>> >> >
>> >> > However now I would like to start accessing elements.
>> >> >
>> >> > I tried the following:
>> >> >
>> >> >
>> >> > InputStream is = new FileInputStream("note.xsd");
>> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
>> >> >
>> >> >
>> >> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >> >
>> >> > System.out.println(objectTable.getCount());
>> >> >
>> >> >
>> >> > This prints out 0. Should it not print out the number of elements?
>> >> >
>> >> >
>> >> > notes.xsd is as follows:
>> >> >
>> >> >
>> >> >
>> >> > <?xml version="1.0"?>
>> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >> >
>> >> > <xs:element name="note">
>> >> >  <xs:complexType>
>> >> >    <xs:sequence>
>> >> >      <xs:element name="to" type="xs:string"/>
>> >> >      <xs:element name="from" type="xs:string"/>
>> >> >      <xs:element name="heading" type="xs:string"/>
>> >> >      <xs:element name="body" type="xs:string"/>
>> >> >    </xs:sequence>
>> >> >  </xs:complexType>
>> >> > </xs:element>
>> >> >
>> >> > </xs:schema>
>> >> >
>> >> >
>> >> >
>> >> > Thanks,
>> >> >
>> >> > Patrick
>> >> >
>> >>
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Cool, thanks :)
Is it a bug or?

Maybe you could include some code showing the common uses of the API.

I basically want to be able to extract the elements of a schema and then
display it using a
JTree.

Patrick

On Fri, Apr 10, 2009 at 7:24 PM, Benson Margulies <bi...@gmail.com>wrote:

> I'm a bit buried under Passover, but I'll sort this out over the
> weekend some time.
>
> On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > Version 1.4.4
> >
> > On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <bimargulies@gmail.com
> >wrote:
> >
> >> You don't have a target namespace.... but that should be OK. What
> >> version have you grabbed?
> >>
> >> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <ho...@gmail.com>
> >> wrote:
> >> > Hi,
> >> > Trying to start using the API. Following the instructions in the
> tutorial
> >> I
> >> > can get the schema to print fine.
> >> >
> >> > However now I would like to start accessing elements.
> >> >
> >> > I tried the following:
> >> >
> >> >
> >> > InputStream is = new FileInputStream("note.xsd");
> >> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> >> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
> >> >
> >> >
> >> > XmlSchemaObjectTable objectTable = schema.getElements();
> >> >
> >> > System.out.println(objectTable.getCount());
> >> >
> >> >
> >> > This prints out 0. Should it not print out the number of elements?
> >> >
> >> >
> >> > notes.xsd is as follows:
> >> >
> >> >
> >> >
> >> > <?xml version="1.0"?>
> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >> >
> >> > <xs:element name="note">
> >> >  <xs:complexType>
> >> >    <xs:sequence>
> >> >      <xs:element name="to" type="xs:string"/>
> >> >      <xs:element name="from" type="xs:string"/>
> >> >      <xs:element name="heading" type="xs:string"/>
> >> >      <xs:element name="body" type="xs:string"/>
> >> >    </xs:sequence>
> >> >  </xs:complexType>
> >> > </xs:element>
> >> >
> >> > </xs:schema>
> >> >
> >> >
> >> >
> >> > Thanks,
> >> >
> >> > Patrick
> >> >
> >>
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
I'm a bit buried under Passover, but I'll sort this out over the
weekend some time.

On Fri, Apr 10, 2009 at 11:46 AM, Patrick Kiernan <ho...@gmail.com> wrote:
> Version 1.4.4
>
> On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> You don't have a target namespace.... but that should be OK. What
>> version have you grabbed?
>>
>> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <ho...@gmail.com>
>> wrote:
>> > Hi,
>> > Trying to start using the API. Following the instructions in the tutorial
>> I
>> > can get the schema to print fine.
>> >
>> > However now I would like to start accessing elements.
>> >
>> > I tried the following:
>> >
>> >
>> > InputStream is = new FileInputStream("note.xsd");
>> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
>> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
>> >
>> >
>> > XmlSchemaObjectTable objectTable = schema.getElements();
>> >
>> > System.out.println(objectTable.getCount());
>> >
>> >
>> > This prints out 0. Should it not print out the number of elements?
>> >
>> >
>> > notes.xsd is as follows:
>> >
>> >
>> >
>> > <?xml version="1.0"?>
>> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>> >
>> > <xs:element name="note">
>> >  <xs:complexType>
>> >    <xs:sequence>
>> >      <xs:element name="to" type="xs:string"/>
>> >      <xs:element name="from" type="xs:string"/>
>> >      <xs:element name="heading" type="xs:string"/>
>> >      <xs:element name="body" type="xs:string"/>
>> >    </xs:sequence>
>> >  </xs:complexType>
>> > </xs:element>
>> >
>> > </xs:schema>
>> >
>> >
>> >
>> > Thanks,
>> >
>> > Patrick
>> >
>>
>

Re: Using Apache XMLSchema API

Posted by Patrick Kiernan <ho...@gmail.com>.
Version 1.4.4

On Fri, Apr 10, 2009 at 1:55 PM, Benson Margulies <bi...@gmail.com>wrote:

> You don't have a target namespace.... but that should be OK. What
> version have you grabbed?
>
> On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <ho...@gmail.com>
> wrote:
> > Hi,
> > Trying to start using the API. Following the instructions in the tutorial
> I
> > can get the schema to print fine.
> >
> > However now I would like to start accessing elements.
> >
> > I tried the following:
> >
> >
> > InputStream is = new FileInputStream("note.xsd");
> > XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> > XmlSchema schema = schemaCol.read(new StreamSource(is), null);
> >
> >
> > XmlSchemaObjectTable objectTable = schema.getElements();
> >
> > System.out.println(objectTable.getCount());
> >
> >
> > This prints out 0. Should it not print out the number of elements?
> >
> >
> > notes.xsd is as follows:
> >
> >
> >
> > <?xml version="1.0"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >
> > <xs:element name="note">
> >  <xs:complexType>
> >    <xs:sequence>
> >      <xs:element name="to" type="xs:string"/>
> >      <xs:element name="from" type="xs:string"/>
> >      <xs:element name="heading" type="xs:string"/>
> >      <xs:element name="body" type="xs:string"/>
> >    </xs:sequence>
> >  </xs:complexType>
> > </xs:element>
> >
> > </xs:schema>
> >
> >
> >
> > Thanks,
> >
> > Patrick
> >
>

Re: Using Apache XMLSchema API

Posted by Benson Margulies <bi...@gmail.com>.
You don't have a target namespace.... but that should be OK. What
version have you grabbed?

On Fri, Apr 10, 2009 at 8:11 AM, Patrick Kiernan <ho...@gmail.com> wrote:
> Hi,
> Trying to start using the API. Following the instructions in the tutorial I
> can get the schema to print fine.
>
> However now I would like to start accessing elements.
>
> I tried the following:
>
>
> InputStream is = new FileInputStream("note.xsd");
> XmlSchemaCollection schemaCol = new XmlSchemaCollection();
> XmlSchema schema = schemaCol.read(new StreamSource(is), null);
>
>
> XmlSchemaObjectTable objectTable = schema.getElements();
>
> System.out.println(objectTable.getCount());
>
>
> This prints out 0. Should it not print out the number of elements?
>
>
> notes.xsd is as follows:
>
>
>
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="note">
>  <xs:complexType>
>    <xs:sequence>
>      <xs:element name="to" type="xs:string"/>
>      <xs:element name="from" type="xs:string"/>
>      <xs:element name="heading" type="xs:string"/>
>      <xs:element name="body" type="xs:string"/>
>    </xs:sequence>
>  </xs:complexType>
> </xs:element>
>
> </xs:schema>
>
>
>
> Thanks,
>
> Patrick
>