• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating XML against .xsd (schemata)

 
Mike Cronin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic