• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validating XML against .xsd (schemata)

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
reply
    Bookmark Topic Watch Topic
  • New Topic