• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Validating XML with a XSD

 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first guess would be that it's a problem with the XML/XSD, not the Java code. Can you post them?

Moving to our XML forum...
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked my XML again and it turns out I was using the wrong version of a spec. The java code was fine. Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic