Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with parsing xml against schema using SAX2Parser

 
Lakshmi Ramachandran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Caroline Iux
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic