As with XSLT transformation explained in the previous volume, we can easily perform this check if we use the standard API "JAXP (Java API for XML Processing)" included in J2SE 5.0.
List1 shows an example of a program created in JAXP that performs a validity check.
*/ public static Fusion Dictionary read Dictionary Xml(Input Stream unigrams, Input Stream bigrams) throws SAXException, IOException, Parser Configuration Exception /** * Runs the queries against the supplied XML file.
* @param xmlfile The XML file that shall be queried. * @throws Parser Configuration Exception Parser confiuration exception * @throws SAXException SAX exception * @throws IOException If unable to read the stream */ public static boolean compare XMLContent(final Input Source content1,final Input Source content2) throws Parser Configuration Exception, SAXException, IOException /** * Valorizza una risorsa prototipo con gli elementi dell'xml che rappresenta una risorsa specifica.
* @return A fully configured [email protected] SAXReader}.
To be prepared for Section 4, you must have a firm understanding of XML Schema basic grammar, as well as knowledge covering a wide range of concepts, including XML Schema design methods incorporating XML namespaces, and include / import methods for other XML Schema.
As we can see in List1, when a validity check is performed using JAXP, an instance of the class parsers.
If the reference to the XML Schema (attribute no Namespace Schema Location or schema Location) is coded directly in the XML document, you can omit the second argument.
Even if W3C XML Schema is provided with Schema .., parsing would fail, since Validating(true) was specified, and if a DTD is absent.
2) If we only want to do validation with W3C XML Schema, then we shouldn't specify Validating(true), which is required only for DTD validation.
But there, are few catches here, which I wish to share.
1) If Validating(true) is specified, then a DTD is mandatory.