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 8.1 KiB

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