Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ended up using this:</p> <pre><code>import org.apache.xerces.parsers.SAXParser; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import java.io.IOException; . . . try { SAXParser parser = new SAXParser(); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "http://your_url_schema_location"); Validator handler = new Validator(); parser.setErrorHandler(handler); parser.parse("file:///" + "/home/user/myfile.xml"); } catch (SAXException e) { e.printStackTrace(); } catch (IOException ex) { e.printStackTrace(); } class Validator extends DefaultHandler { public boolean validationError = false; public SAXParseException saxParseException = null; public void error(SAXParseException exception) throws SAXException { validationError = true; saxParseException = exception; } public void fatalError(SAXParseException exception) throws SAXException { validationError = true; saxParseException = exception; } public void warning(SAXParseException exception) throws SAXException { } } </code></pre> <p>Remember to change:</p> <p>1) The parameter <strong>"http://your_url_schema_location"</strong> for you xsd file location.</p> <p>2) The string <strong>"/home/user/myfile.xml"</strong> for the one pointing to your xml file. </p> <p>I didn't have to set the variable: <code>-Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory</code> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload