Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is no 100% foolproof process for determining how to validate an arbitrary XML document.</p> <p>For example, this version 2.4 <a href="http://en.wikipedia.org/wiki/Deployment_Descriptor" rel="nofollow noreferrer">web application deployment descriptor</a> specifies a <a href="http://www.w3.org/XML/Schema" rel="nofollow noreferrer">W3 schema</a> to validate the document:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt; </code></pre> <p>However, this is an equally valid way of expressing the same thing:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"&gt; </code></pre> <p><a href="http://relaxng.org/" rel="nofollow noreferrer">RELAX NG</a> doesn't seem to have a mechanism that offers <em>any</em> hints in the document that you should use it. Validation mechanisms are determined by document consumers, not producers. If I'm not mistaken, this was one of the impetuses driving the switch from DTD to more modern validation mechanisms.</p> <p>In my opinion, your best bet is to tailor the mechanism detector to the set of document types you are processing, reading header information and interpreting it as appropriate. The <a href="http://java.sun.com/javase/6/docs/api/javax/xml/stream/package-summary.html" rel="nofollow noreferrer">StAX parser</a> is good for this - because it is a pull mechanism, you can just read the start of the file and then quit parsing on the first element.</p> <p><a href="http://illegalargumentexception.blogspot.com/2009/02/java-finding-validation-mechanism-for.html" rel="nofollow noreferrer">Link to more of the same and sample code and whatnot.</a></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