Parsing XML Schema

Status
Not open for further replies.

pradeepsarathy

Usenet Archive
Joined
Mar 10, 2006
Messages
7
Reaction score
0
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
 

George Bina

Usenet Archive
Joined
Jan 30, 2004
Messages
134
Reaction score
0
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
 

pradeepsarathy

Usenet Archive
Joined
Mar 10, 2006
Messages
7
Reaction score
0
Hi George,
Thanks for the reply,
I have another question.
Is it possible to override SAX Handler
methods(startDocument,endDocument...etc).
 

George Bina

Usenet Archive
Joined
Jan 30, 2004
Messages
134
Reaction score
0
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
 

pradeepsarathy

Usenet Archive
Joined
Mar 10, 2006
Messages
7
Reaction score
0
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.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown So at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.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)
 

George Bina

Usenet Archive
Joined
Jan 30, 2004
Messages
134
Reaction score
0
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
 

pradeepsarathy

Usenet Archive
Joined
Mar 10, 2006
Messages
7
Reaction score
0
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>
 

Johannes Koch

Usenet Archive
Joined
Nov 14, 2000
Messages
801
Reaction score
0
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.
 
Status
Not open for further replies.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top