468,544 Members | 1,820 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

Parsing XML Schema

Hi all,
Does the SAX parser has eventhandlers for parsing xml schema.
Can we parse the xml schema the same way as we parse the xml document
using SAX Parser.

Thanks in advance.
-pradeep

Mar 10 '06 #1
8 2438
Hi,

XML Schema is represented in XML documents so you can parse them as you
can parse any other XML document. However that will not check that you
have a correct/valid schema file.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Mar 10 '06 #2
Hi George,
Thanks for the reply,
I have another question.
Is it possible to override SAX Handler
methods(startDocument,endDocument...etc).

Mar 10 '06 #3
Hi,

SAX specifies an interface, ContentHandler, thus no implementation, so
you need to write an implementation of ContentHandler if you set one on
the parser. Now there is a noop helper implementation for
ContentHandler in the DefaultHandler class and if you inherit from that
then yes, you need to overwrite the methods you are interested in.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Mar 12 '06 #4
Hi george,
I tried parsing the XML Schema through SAX,but got the following
error.Can u please help me figure out where the problem is?
The schema i used is....

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
</xs:schema>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="onlyNumeric" type="xs:decimal"/>
<xs:element name="onlyAlphabet" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

org.xml.sax.SAXParseException: The markup in the document following the
root element must be well-formed.
at
com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(Unknown
Source)
at
com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.fatalError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner .reportFatalError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl$TrailingMiscDispatcher.dispatch(Unkno wn
So
at
com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.Abstrac tSAXParser.parse(Unknown
Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at processXmlSchema.start(processXmlSchema.java:48)
at processXmlSchema.main(processXmlSchema.java:32)

Mar 13 '06 #5
Hi,

That is not a wellformed document so it is not XML:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
</xs:schema>
^^^^^^^^^^^^^^^^
You already closed the document element here so you cannot have next
another element:

<xs:element name="root">
....

You probably want:

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

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="onlyNumeric" type="xs:decimal"/>
<xs:element name="onlyAlphabet" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Mar 13 '06 #6
Thanx George,
It's successfully parsing the xml shema,but now i have a different
problem.
How do i parse the attribute (name/type) using SAX.
Is there a way?I wen through the API but could not find a method for
parsing the attributes.
Can you please help me?
Thanx in advance.

I am using the same schema.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="onlyNumeric" type="xs:decimal"/>
<xs:element name="onlyAlphabet" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Mar 13 '06 #7
pr************@gmail.com wrote:
Thanx George,
It's successfully parsing the xml shema,but now i have a different
problem.
How do i parse the attribute (name/type) using SAX.
Is there a way?I wen through the API but could not find a method for
parsing the attributes.


The SAX ContentHandler interface provides a method

public void startElement(String namespaceURI,
String localName,
String qName,
Attributes atts)
throws SAXException

Here you have access to the attributes. See the documentation for the
Attributes interface.

--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Mar 13 '06 #8
Thanx johannes.Will get back to you shortly.

Mar 13 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Christophe Vanfleteren | last post: by
4 posts views Thread by Pushya | last post: by
2 posts views Thread by Mike | last post: by
1 post views Thread by padmagvs | last post: by
1 post views Thread by JJadhav | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.