Problem with XML Validation 2003-05-06 - By Vamsi Atluri
Hi,
I am using Xerces 2.4.0 for parsing XML files and validating the XML against the schema file. I created an entity resolver class which loads the XSD file from the local disk and returns it as an InputStream. I am setting this entity resolver on the parser in this way:
DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.setEntityResolver(new TestEntityResolver()); parser.setFeature( "http://xml.org/sax/features/validation", true); parser.setFeature( "http://xml.org/sax/features/namespaces", true); parser.setFeature( "http://apache.org/xml/features/validation/schema", true); parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", true);
My entity resolver's resolveEntity method works in this way:
String xsdFile = "TestSchema.xsd"; InputSource is = new InputSource(new FileReader(xsdFile)); return is;
I also created a small ErrorHandler that prints out any SAXParseException that it gets.
Now, when I try to parse the XML string, I get the following error printed out by my ErrorHandler:
cvc-elt.1: Cannot find the declaration of element 'RootElement'.
The XML String I am trying to parse is of the form:
<RootElement><Elem1>Data1</Elem1><Elem2>Data2</Elem2></RootElement>
My XSD file has the following in the beginning of the XSD file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
And the RootElement is definitely defined in the XSD file. I ran a search for this error through google and some of the discussion boards said that there was a bug with older versions of Xerces, which is supposed to be fixed.
Any help would be grately appreciated.
Thank you, -Vamsi
__________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|