GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Validating XML against .xsd (schemata) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Validating XML against .xsd (schemata)" Watch "Validating XML against .xsd (schemata)" New topic
Author

Validating XML against .xsd (schemata)

Mike Cronin
Greenhorn

Joined: Apr 17, 2002
Posts: 25
Hi all,
Just a heads-up for anyone interested in validating XML against it's schemata.
Sun's Multi-Schema XML Validator (MSV) software works great.
Read about and download the software free at http://dcb.sun.com/practices/devnotebook/xml_msv.jsp
One note, if you are using a DOM object, the example provided by SUN does not "appear" to be correct as the .verify() method does not accept a DOM argument...
// check the validity of this DOM.
if( schema.newVerifier().verify(dom) ) {
// document is valid
} else {
// document is NOT valid
}

My code uses an InputSource object instead...
// Establish a StringReader object to the xmlData
StringReader sr = new StringReader(xmlData);
// Store the xmlData to an InputSource object
InputSource input = new InputSource(sr);
// When the xmlData is valid
if (schema.newVerifier().verify(input)) {
// Establish a new StringReader object
StringReader sr2 = new StringReader(xmlData);
// Store the xmlData to a new InputSource object
InputSource input2 = new InputSource(sr2);
// Establish a new DOMParser object
DOMParser parser = new DOMParser();
// When the DOMParser is not null
if (parser != null) {
// Parse the xmlData
parser.parse(input2);
// Create the Document object for the xmlData
dom = parser.getDocument();
}
}
else {
// document is NOT valid
}
Hope this helps someone!
Best Regards!!!
Mike Cronin
Data On Call
kiran manohar
Ranch Hand

Joined: Sep 28, 2003
Posts: 49
hi mike
The Sun's Multi-Schema XML Validator (MSV) software which u have listed in ur thread doesnot goto the specified site. could u help me get the software,bcoz i have a requirement which needs me to parse any xml string and store its data into a java object and vice versa
Thanks
Kiranmanohar
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by kiran manohar:
hi mike
The Sun's Multi-Schema XML Validator (MSV) software which u have listed in ur thread doesnot goto the specified site. could u help me get the software,bcoz i have a requirement which needs me to parse any xml string and store its data into a java object and vice versa
Thanks
Kiranmanohar

Kiran, For your requirement, you have to really look either castor or jbind.
http://castor.exolab.org
http://jbind.sourceforge.net/
the sun msv link is http://wwws.sun.com/software/xml/developers/multischema/


Spritle Software Blogs
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Validating XML against .xsd (schemata)