LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   XML Schemas and Java XML Parsers (https://www.linuxquestions.org/questions/programming-9/xml-schemas-and-java-xml-parsers-713207/)

manolakis 03-20-2009 02:43 PM

XML Schemas and Java XML Parsers
 
Hi there,

I have seen a number of tutorials for parsing an XML file with Java XML Parsers but I have failed to find any tutorial for validating an XML file according to its schema with a Java Parser.
Can anyone list any tutorial or give some sample code.

Many thanks.

paulsm4 03-20-2009 08:51 PM

The standard parsers that come with the JDK should all be validating parsers these days. So all you have to do is turn on validation when you create the object:
Code:

  // EXAMPLE:
  SAXParserFactory factory = SAXParserFactory.newInstance();
  factory.setValidating(true);

Here's a more elaborate example (you can easily find better, newer and more comprehensive examples, I'm sure):

http://java.sun.com/j2ee/1.4/docs/tu.../JAXPDOM8.html

'Hope that helps .. PSM


All times are GMT -5. The time now is 12:35 PM.