• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem with parsing xml against schema using SAX2Parser

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic