473,414 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 2676
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ewan B | last post by:
Hi, I'm using Xerces to parse XML files using SAX2, and am wondering if there is any information as to what exceptions are being thrown when certain validation errors occur. Taking a simple...
2
by: Christophe Vanfleteren | last post by:
Hello, I'm parsing xml that is returned by the Amazon webservices (using their REST interface). Their dev-heavy.xsd has the following entry: <xs:element name="Track"> <xs:complexType>...
4
by: Pushya | last post by:
Hello - I am trying to parse a .XSD file to obtain information about element name and type in the file. I have been trying to find some kind of documentation for Schema Parsing. All I come...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
2
by: Mike | last post by:
Hi! I have an Excel 2003 Schema I need to parse to extract elements names. I am puzzled which System.Xml object can help me. Here's the example of my schema: I need to get a collection of...
1
by: christian.eickhoff | last post by:
Hi, I have a general question regarding the parsing of XSD files, referenced within the namespace using Apache Xerces 2.7.0 (CDT). My current c++ application can parse and validate an XML file...
1
by: padmagvs | last post by:
I am working on some code which parses wsdl . I have a complex wsdl which is failing to parse . I have to modify this wsdl for parsing . wanted to know the complex wsdl i am using is as per...
1
by: JJadhav | last post by:
I have written the following schema file: <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.abc.com/DDSchema" targetNamespace="http://www.abc.com/DDSchema"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.