Ok, thanks for your help. On Thu, Apr 16, 2009 at 3:44 PM, Benson Margulies <bimargul...@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 <hossb...@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 < > bimargul...@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 <hossb...@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 < > >> bimargul...@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 <hossb...@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 < > >> bimargul...@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 < > hossb...@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 < > >> >> >> bimargul...@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. > >> >> >> >> > >> >> >> > > >> >> >> > >> >> > > >> >> > >> > > >> > > >