4.5. XML Validation

Most XML parsers provide a validation capability. Validation means that beyond just ensuring that the XML is well-formed, the parser will also verify that the XML document conforms to the DTD or XML Schema. Unfortunately, telling a parser whether or not it should use validation is one of the things that is implementation-dependent, so there is no portable way to turn validation on or off.

For the Apache Xerces parser, validation is turned on and off by a setFeature() method. For SAX, you can call setFeature() on the org.xml.sax.XMLReader object (if you're using JAXP, you can obtain a reference to this object by calling the getXMLReader() method of the javax.xml.parsers.SAXParser object). For DOM, you must call the setFeature() ...

Get J2EE™ and JAX™: Developing Web Applications and Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.