aspose file tools*
The moose likes XML and Related Technologies and the fly likes Problem with parsing xml against schema using SAX2Parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem with parsing xml against schema using SAX2Parser" Watch "Problem with parsing xml against schema using SAX2Parser" New topic
Author

Problem with parsing xml against schema using SAX2Parser

Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
Hi friends,
I am facing problem with parsing xml against schema using SAX2Parser with Xerces. I have created the xml file which has the following structure
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\SchemaValidation\testschema.xsd">
<RoleNo>XI-12</RoleNo>
<Age>12</Age>
</Person>
Its corresponding schema is
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name ="Person">
<xsd:complexType>
<xsd:sequence >
<xsd:element name="RoleNo" type="xsd:string" />
<xsd:element name="Age" type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
When I run the application to parse and validate, it checks for well-formedness correctly but does not validate against the schema. Instead gives the following error message:
Element Type "Person" must be declared.
Attribute "xsi:noNamespaceSchemaLocation" must be declared for element type "Person".
Element Type "RoleNo" must be declared.
Element Type "Age" must be declared.
I have the following
XMLReader parser;
parser = new SAXParser();
1. parser.setFeature(
"http://xml.org/sax/features/validation", true);
parser.setErrorHandler(new ValidityErrorReporter());
-------------->ValidityErrorReporter is my errorhandler class.
COULD NOT GET THROUGH BY THIS METHOD.
2.Tried to set the property by
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",parser.getProperty("http://apache.org/xml/properties/schema/external-noNamespaceSche maLocation"));
The method getProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation")
is not able to recognise the property "external-schemaLocation
" and "external-noNamespaceSchemaLocation".
Please respond to my query as soon as possible.
Thanks & Regards
Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
Hi!
I get exactly the same type of error when running the examples that come with xerces.
And I have no idea why it's happening....

Anybody?
/Manuel


<a href="http://www.newinstance.net" target="_blank" rel="nofollow">http://www.newinstance.net</a>
Caroline Iux
Ranch Hand

Joined: May 14, 2001
Posts: 103
Check the following thread:
http://www.javaranch.com/ubb/Forum31/HTML/000931.html
Also, try to put your schema file in your web folder and try to change your xml like this:
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost/testschema.xsd">

[This message has been edited by Caroline Iux (edited July 02, 2001).]
Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
Hi,
Thanks for your response.
I tried it like you said and placed both documents under wwwroot
but I get exactly the same error. Xerces can't find the schema and I don't know where to put it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with parsing xml against schema using SAX2Parser
 
Similar Threads
validation question od XML schemas
URGENT - Grammar in XML for Schema
How to use DomParser.parse() to parse an XML String instead of the XML location?
non recoverable error unexpected
Validating XML against Schema.