This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 41122
    
  45
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'.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: validating xml file against a specific schema using jaxp sax parser
 
Similar Threads
Error in XSD Parsing - Imported XSD not being loaded
How can I validate the XML schema with XML files using localpath?
Imported XSD not being loaded- Parsing error
validating xml??
xerces : Parsingproblem when "include" one or more Schema in another