Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 10th, 2006, 09:25 AM
pradeepsarathy@gmail.com
Guest
 
Posts: n/a
Default 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

  #2  
Old March 10th, 2006, 09:35 AM
George Bina
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

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

  #3  
Old March 10th, 2006, 01:35 PM
pradeepsarathy@gmail.com
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

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

  #4  
Old March 12th, 2006, 02:45 AM
George Bina
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

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

  #5  
Old March 13th, 2006, 06:55 AM
pradeepsarathy@gmail.com
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

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)

  #6  
Old March 13th, 2006, 07:55 AM
George Bina
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

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

  #7  
Old March 13th, 2006, 08:55 AM
pradeepsarathy@gmail.com
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

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>

  #8  
Old March 13th, 2006, 09:25 AM
Johannes Koch
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

pradeepsarathy@gmail.com wrote:
[color=blue]
> 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.[/color]

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.)
  #9  
Old March 13th, 2006, 10:05 AM
pradeepsarathy@gmail.com
Guest
 
Posts: n/a
Default Re: Parsing XML Schema

Thanx johannes.Will get back to you shortly.

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles