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