This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML Schema validation from java using Xercer 1.4.4 and DOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Schema validation from java using Xercer 1.4.4 and DOM" Watch "XML Schema validation from java using Xercer 1.4.4 and DOM" New topic
Author

XML Schema validation from java using Xercer 1.4.4 and DOM

Ric Gupta
Greenhorn

Joined: Aug 08, 2003
Posts: 4
Hi,
I am trying to validate an XML file using Schemas at parsing time using DOM Parser. Set the following features of DOM parser:
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
parser.setFeature("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", true);
parser.setFeature("http://apache.org/xml/features/validation/dynamic", true);
After setting all of these features also, the XML is not validated againt schema.
Schema declaration contains header as:
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="qualified">
XML header is :
<customer-order-status
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="XMLSchema.xsd">
Also tried to give full path to Schema and also namespace but of no use.
Can anybody help?
Ric
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
whats the error message you are getting ?


Spritle Software Blogs
Ric Gupta
Greenhorn

Joined: Aug 08, 2003
Posts: 4
Getting no error message but the XML is not getting validated against Schema. for eg. I added type for one element as "date"
<element name="value" minOccurs="1" maxOccurs="1" type="date"/>
If I write a String in XML file like
<value>aa</value>
I am not getting any parse exception or error. The XML file is sucessfully parsed.
Howie Jiang
Greenhorn

Joined: Aug 25, 2003
Posts: 26
try this:
parser.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
"XMLSchema.xsd");
and drop tell us how is the result..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XML Schema validation from java using Xercer 1.4.4 and DOM
 
It's not a secret anymore!