I am trying to validate my XML against a XSD file and I have run into some trouble. Here is a function I use
public void parseWithSAX() throws Exception
{
SAXParser p=new SAXParser();
p.setFeature( "http://xml.org/sax/features/validation",
true);
p.setFeature( "http://apache.org/xml/features/validation/schema", true );
p.setFeature(
"http://apache.org/xml/features/validation/schema-full-checking",
true );
p.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation","http://ACORD.org/Standards/Life/2 http://localhost:8080/axis/Life.xsd");
p.parse("file:///D:/zSample_XML.xml");
}
This results in the following error
[Error] zSample_XML.xml:2:178: cvc-elt.1: Cannot find the declaration of element 'TXLife'. I am using JDK 1.3 and Xerces 2.5. My classpath has xercesImpl, xml-apis and xmlParsersAPI jars. The API does not seem to be able to locate my XSD file. I am pretty sure about this since when I turn schema validation feature off it looks for a DTD instead. I cannot seem to find a way to make it find my XSD. I have even tried putting the XSD on file and then pointing to it with "file:///bla" and using relative paths. I also tried mentioning the XSD location in the XML instead of the mentioning it in the code and that didnt work either. The http URL for the XSD is valid and I verified it. Any suggestions ?