You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

schemavalidate.html 7.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  18. <title>SchemaValidate Task</title>
  19. </head>
  20. <body>
  21. <h2 id="schemavalidate">SchemaValidate</h2>
  22. <h3>Description</h3>
  23. <p>This <code>schemavalidate</code> task validates XML files described by an XML Schema. The task
  24. extends the <code>XmlValidate</code> task with XSD-specific features.</p>
  25. <ol>
  26. <li>The parser is created validating and namespace aware.</li>
  27. <li>Validation is turned on.</li>
  28. <li>Schema validation is turned on.</li>
  29. <li>Any no-namespace schema URL or file supplied is used as the no-namespace schema.</li>
  30. <li>All nested schema declarations are turned into the list of namespace-url bindings for schema
  31. lookup.</li>
  32. </ol>
  33. <p>Note that nested catalogs are still used for lookup of the URLs given as the sources of schema
  34. documents, so you can still delegate lookup to a catalog, you just need to list all schema URIs and
  35. their URL equivalents.</p>
  36. <p>This task supports the use of nested</p>
  37. <ul>
  38. <li><a href="../Types/xmlcatalog.html"><code>&lt;xmlcatalog&gt;</code></a> elements</li>
  39. <li><code>&lt;schema&gt;</code> elements, that bind a namespace URI to a URL or a local
  40. filename.</li>
  41. <li><code>&lt;dtd&gt;</code> elements which are used to resolve DTDs and entities.</li>
  42. <li><code>&lt;attribute&gt;</code> elements which are used to set features on the parser. These
  43. can be any number
  44. of <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"
  45. target="_top"><code>http://xml.org/sax/features/</code></a> or other features that your parser
  46. may support.</li>
  47. <li><code>&lt;property&gt;</code> elements, containing string properties</li>
  48. </ul>
  49. <p>The task only supports SAX2 or later parsers: it is an error to specify a SAX1 parser.</p>
  50. <h3>Parameters</h3>
  51. <table class="attr">
  52. <tr>
  53. <th>Attribute</th>
  54. <th>Description</th>
  55. <th>Required</th>
  56. </tr>
  57. <tr>
  58. <td>classname</td>
  59. <td>the parser to use.</td>
  60. <td>No</td>
  61. </tr>
  62. <tr>
  63. <td>classpathref</td>
  64. <td>where to find the parser class. Optionally can use an
  65. embedded <code>&lt;classpath&gt;</code> element.</td>
  66. <td>No</td>
  67. </tr>
  68. <tr>
  69. <td>disableDTD</td>
  70. <td>Flag to disable DTD support. DTD support is needed to validate XSD files themselves, amongst
  71. others.</td>
  72. <td>No; default <q>false</q></td>
  73. </tr>
  74. <tr>
  75. <td>failonerror</td>
  76. <td>fails on a error if set to <q>true</q>.</td>
  77. <td>No; defaults to <q>true</q></td>
  78. </tr>
  79. <tr>
  80. <td>file</td>
  81. <td>the file(s) you want to check (optionally use an embedded fileset).</td>
  82. <td>No</td>
  83. </tr>
  84. <tr>
  85. <td>fullchecking</td>
  86. <td>enable full schema checking. Slow but strict.</td>
  87. <td>No; default <q>true</q></td>
  88. </tr>
  89. <tr>
  90. <td>lenient</td>
  91. <td>if <q>true</q>, only check the XML document is well formed</td>
  92. <td>No</td>
  93. </tr>
  94. <tr>
  95. <td>noNamespaceFile</td>
  96. <td>filename of a no-namespace XSD file to provide the schema for no-namespace XML content</td>
  97. <td>No</td>
  98. </tr>
  99. <tr>
  100. <td>noNamespaceURL</td>
  101. <td>URL of a no-namespace XSD file to provide the schema for no-namespace XML content</td>
  102. <td>No</td>
  103. </tr>
  104. <tr>
  105. <td>warn</td>
  106. <td>log parser warn events</td>
  107. <td>No</td>
  108. </tr>
  109. </table>
  110. <h3 id="nested">Parameters specified as nested elements</h3>
  111. <h4>schema</h4>
  112. <p>Identify the name and location of a schema that may be used in validating the document(s).</p>
  113. <table class="attr">
  114. <tr>
  115. <th>Attribute</th>
  116. <th>Description</th>
  117. <th>Required</th>
  118. </tr>
  119. <tr>
  120. <td>namespace</td>
  121. <td>URI of the schema namespace</td>
  122. <td>Yes</td>
  123. </tr>
  124. <tr>
  125. <td>url</td>
  126. <td>URL of the schema</td>
  127. <td rowspan="2">Exactly one of the two</td>
  128. </tr>
  129. <tr>
  130. <td>file</td>
  131. <td class="left">file of the schema</td>
  132. </tr>
  133. </table>
  134. <h4>dtd</h4>
  135. <p><code>&lt;dtd&gt;</code> is used to specify different locations for DTD resolution.</p>
  136. <table class="attr">
  137. <tr>
  138. <th>Attribute</th>
  139. <th>Description</th>
  140. <th>Required</th>
  141. </tr>
  142. <tr>
  143. <td>publicId</td>
  144. <td>Public ID of the DTD to resolve</td>
  145. <td>Yes</td>
  146. </tr>
  147. <tr>
  148. <td>location</td>
  149. <td>Location of the DTD to use, which can be a file,
  150. a resource, or a URL</td>
  151. <td>Yes</td>
  152. </tr>
  153. </table>
  154. <h4>xmlcatalog</h4>
  155. <p>The <a href="../Types/xmlcatalog.html"><code>&lt;xmlcatalog&gt;</code></a> element is used to
  156. perform entity resolution.</p>
  157. <h4>attribute</h4>
  158. <p>The <code>&lt;attribute&gt;</code> element is used to set parser features.<br/>Features usable
  159. with the Xerces parser are defined here: <a href="https://xml.apache.org/xerces-j/features.html"
  160. target="_top">Setting features</a><br/>SAX features are defined
  161. here: <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"
  162. target="_top"><code>http://xml.org/sax/features/</code></a></p>
  163. <table class="attr">
  164. <tr>
  165. <th>Attribute</th>
  166. <th>Description</th>
  167. <th>Required</th>
  168. </tr>
  169. <tr>
  170. <td>name</td>
  171. <td>The name of the feature</td>
  172. <td>Yes</td>
  173. </tr>
  174. <tr>
  175. <td>value</td>
  176. <td>The boolean value of the feature</td>
  177. <td>Yes</td>
  178. </tr>
  179. </table>
  180. <h4>property</h4>
  181. <p>The <code>&lt;property&gt;</code> element is used to set properties. These properties are
  182. defined here for the Xerces XML parser
  183. implementation: <a href="https://xml.apache.org/xerces-j/properties.html" target="_top">XML Parser
  184. properties</a>. Properties can be used to set the schema used to validate the XML file.
  185. </p>
  186. <table class="attr">
  187. <tr>
  188. <th>Attribute</th>
  189. <th>Description</th>
  190. <th>Required</th>
  191. </tr>
  192. <tr>
  193. <td>name</td>
  194. <td>The name of the feature</td>
  195. <td>Yes</td>
  196. </tr>
  197. <tr>
  198. <td>value</td>
  199. <td>The string value of the property</td>
  200. <td>Yes</td>
  201. </tr>
  202. </table>
  203. <h3>Examples</h3>
  204. <pre>
  205. &lt;schemavalidate noNamespaceFile="document.xsd"
  206. file="xml/endpiece.xml"/&gt;</pre>
  207. <p>Validate a document against an XML schema. The document does not declare any schema itself, which
  208. is why the <var>noNamespaceFile</var> is needed.</p>
  209. <pre>
  210. &lt;presetdef name="validate-soap"&gt;
  211. &lt;schemavalidate&gt;
  212. &lt;schema namespace="http://schemas.xmlsoap.org/ws/2003/03/addressing"
  213. file="${soap.dir}/ws-addressing.xsd"/&gt;
  214. &lt;schema namespace="http://www.w3.org/2003/05/soap-envelope"
  215. file="${soap.dir}/soap12.xsd"/&gt;
  216. &lt;schema namespace="http://schemas.xmlsoap.org/wsdl/"
  217. file="${soap.dir}/wsdl.xsd"/&gt;
  218. &lt;schema namespace="http://www.w3.org/2001/XMLSchema"
  219. file="${soap.dir}/XMLSchema.xsd"/&gt;
  220. &lt;/schemavalidate&gt;
  221. &lt;/presetdef&gt;</pre>
  222. <p>Declare a new preset task, <code>&lt;validate-soap&gt;</code>, that validates XSD and WSDL
  223. documents against the relevant specifications. To validate XSD documents, you also
  224. need <samp>XMLSchema.dtd</samp> and <samp>datatypes.dtd</samp> in the same directory
  225. as <samp>XMLSchema.xsd</samp>, or pointed to via the catalog. All these files can be fetched
  226. from <a href="https://www.w3.org/2001/XMLSchema" target="_top">W3C</a>.</p>
  227. <pre>&lt;validate-soap file="xml/test.xsd"/&gt;</pre>
  228. <p>Use the preset task defined above to validate an XML Schema document.</p>
  229. </body>
  230. </html>