• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validating xml file against a specific schema using jaxp sax parser

 
kumar pavan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to validate a soap xml given below
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Body>
<name>pavan</name>
<number>123</number>
</Body>
</Envelope>

to validate against the schema of soap from url "http://www.w3.org/2003/05/soap-envelope". I dont want to have this namespace in the xml. How can I validate against the specified schema using jaxp sax parser?
Please help.

Thanks.
[ May 22, 2008: Message edited by: kumar pavan ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The Code Barn has example codes that show how to validate XML.
 
kumar pavan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply. But it did'nt really serve my purpose. I got the schema object and set it to the SAXParserFactory.

URL url = new URL("http://www.w3.org/2003/05/soap-envelope");
Schema schema = scFactory.newSchema(url);
Validator validator = schema.newValidator();
Source source = new StreamSource(new File("Test.xml"));
validator.validate(source);

xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Body>
<name>pavan</name>
<number>123</number>
</Body>
</Envelope>

Even then I'm getting the exception : cvc-elt.1: Cannot find the declaration of element 'Envelope'.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic