GeeCON Prague 2014*
The moose likes Web Services and the fly likes validating xml file against a specific schema using jaxp sax parser    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Web Services
Bookmark "validating xml file against a specific schema using jaxp sax parser    " Watch "validating xml file against a specific schema using jaxp sax parser    " New topic
Author

validating xml file against a specific schema using jaxp sax parser

kumar pavan
Greenhorn

Joined: May 22, 2008
Posts: 2
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
Marshal

Joined: Mar 22, 2005
Posts: 42058
    
  64
Welcome to JavaRanch.

The Code Barn has example codes that show how to validate XML.


Ping & DNS - my free Android networking tools app
kumar pavan
Greenhorn

Joined: May 22, 2008
Posts: 2
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'.
 
GeeCON Prague 2014
 
subject: validating xml file against a specific schema using jaxp sax parser