OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Need help on parsing XSD files

On 26 Mar 2009, at 09:56 , Neeraj Lal wrote:

> Hi,
> I'm new to XML and need some help on parsing large XSD files which  
> include namespaces and references to other XSD files.
> Which parser is best for this purpose, SAX or DOM?


More seriously, SAX and DOM are interfaces often supported by
parsers, not parsers. Any conforming XML parser will be in a
position to parse an XSD schema document.

> I started with SAX parser but I'm facing some difficulties with it.  
> When I try to parse this:
> <xsd:element ref="ndexia:WitnessAugmentation" minOccurs="0"/>
> I do not get the data in this element.

I bet you do.  I suspect you think you're not getting the data
in the element because you're not getting any data.  But the
element doesn't have any data in it, and by not getting any data
you are in fact getting precisely the data in the element.

> Since, this element does not have a proper ending tag like: </ 
> xsd:element>
> will the ' endElement(String uri, String localName, String qName) '  
> end element method detect the end of element?

If the parser you're using is a conforming parser, yes, it should.
For empty elements of the kind shown, SAX parsers emit an event for
the start of the element, followed immediately by an event for the
end of the element.

> How to extract the ref and minOccurs values from the above element?

If you're using a SAX 2.0 parser, the startElement() method of the
ContentHandler interface will be called with four arguments, the
fourth of which will be an object supporting the Attributes
interface.  Use that interface to get access to the 'ref' attribute
and the 'minOccurs' attribute.

If you're using SAX 1.0, the startElement() method will have two
arguments; the second will be an object supporting the AttributeList

> Also, do the SAX/DOM parser ignore the comment lines of their own?
> Finally, how should I resolve the namespaces and references?

I'm not sure I understand your questions here correctly; if this
doesn't answer them, try again.  Any conforming XML parser, whatever
interfaces it supports, should know how to recognize XML comments
and handle them properly.  You shouldn't need to do anything special
to make that happen.  Some interfaces to XML expose the comments,
so you can read them from your application and perhaps do
useful things with them (for example, write them back out again
in your output); others don't.  Check the documentation.

As for resolving the component references in the XSD schema
documents, -- well, if you need to do that, then either you are
writing a validator, in which case you need more help than I can
conveniently give you here, or you may wish to look into the
use of existing schema-aware tools (Xerces, Saxon, there are
others), which can give you API access not to the XML representation
of the schema, in the schema documents, but to the schema
components themselves (or rather, to data structures representing

* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com
* http://cmsmcq.com/mib
* http://balisage.net

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS