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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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><a name="schemavalidate">SchemaValidate</a></h2>
  22. <h3>Description</h3>
  23. <p>This task validates XML files described by an XML Schema.
  24. The task extends the XmlValidate task with XSD-specific features.</p>
  25. <ol>
  26. <li>The parser is created validating and namespace aware
  27. </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
  31. <li>All nested schema declarations are turned into the list of namespace-url
  32. bindings for schema lookup.
  33. </ol>
  34. Note that nested catalogs are still used for lookup of the URLs given as the
  35. sources of schema documents, so you can still delegate lookup to a catalog, you
  36. just need to list all schema URIs and their URL equivalents.
  37. <p>This task supports the use of nested
  38. <li><a href="../Types/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a> elements</li>
  39. <li> <tt>&lt;schema&gt;</tt> elements, that bind a namespace URI to a URL or a
  40. local filename.
  41. <li><tt>&lt;dtd&gt;</tt> elements which are used to resolve DTDs and entities.</li>
  42. <li><tt>&lt;attribute&gt;</tt> elements which are used to set features on the parser.
  43. These can be any number of
  44. <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a>
  45. or other features that your parser may support.</li>
  46. <li><tt>&lt;property&gt;</tt> elements, containing string properties
  47. </p>
  48. <p>
  49. The task only supports SAX2 or later parsers: it is an error to specify a SAX1
  50. parser.
  51. <h3>Parameters</h3>
  52. <table border="1" cellpadding="2" cellspacing="0">
  53. <tr>
  54. <td valign="top"><b>Attribute</b></td>
  55. <td valign="top"><b>Description</b></td>
  56. <td align="center" valign="top"><b>Required</b></td>
  57. </tr>
  58. <tr>
  59. <td valign="top">classname</td>
  60. <td valign="top">the parser to use.</td>
  61. <td align="center" valign="top">No</td>
  62. </tr>
  63. <tr>
  64. <td valign="top">classpathref</td>
  65. <td valign="top">where to find the parser class.
  66. Optionally can use an embedded <tt>&lt;classpath&gt;</tt> element.</td>
  67. <td align="center" valign="top">No</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">disableDTD</td>
  71. <td valign="top">
  72. Flag to disable DTD support. DTD support is needed to
  73. validate XSD files themselves, amongst others.
  74. </td>
  75. <td valign="top" align="center">No - default false</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">failonerror</td>
  79. <td valign="top">fails on a error if set to true (defaults to true).</td>
  80. <td align="center" valign="top">No</td>
  81. </tr>
  82. <tr>
  83. <td valign="top">file</td>
  84. <td valign="top">the file(s) you want to check. (optionally can use an embedded fileset)</td>
  85. <td valign="top" align="center">No</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">fullchecking</td>
  89. <td valign="top">
  90. enable full schema checking. Slow but strict.
  91. </td>
  92. <td valign="top" align="center">No - default true</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">lenient</td>
  96. <td valign="top">
  97. if true, only check the XML document is well formed
  98. </td>
  99. <td valign="top" align="center">No</td>
  100. </tr>
  101. <tr>
  102. <td valign="top">noNamespaceFile</td>
  103. <td valign="top">
  104. filename of a no-namespace XSD file to provide the
  105. schema for no-namespace XML content.
  106. </td>
  107. <td valign="top" align="center">No</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">noNamespaceURL</td>
  111. <td valign="top">
  112. URL of a no-namespace XSD file to provide the
  113. schema for no-namespace XML content.
  114. </td>
  115. <td valign="top" align="center">No</td>
  116. </tr>
  117. <tr>
  118. <td valign="top">warn</td>
  119. <td valign="top">log parser warn events.</td>
  120. <td align="center" valign="top">No</td>
  121. </tr>
  122. </table>
  123. <h3><a name="nested">Nested Elements</a></h3>
  124. <h4>schema</h4>
  125. <p>
  126. Identify the name and location of a schema that may be used in validating
  127. the document(s).
  128. </p>
  129. <table border="1" cellpadding="2" cellspacing="0">
  130. <tr>
  131. <td width="12%" valign="top"><b>Attribute</b></td>
  132. <td width="78%" valign="top"><b>Description</b></td>
  133. <td width="10%" valign="top"><b>Required</b></td>
  134. </tr>
  135. <tr>
  136. <td valign="top">namespace</td>
  137. <td valign="top">URI of the schema namespace</td>
  138. <td align="center" valign="top">Yes</td>
  139. </tr>
  140. <tr>
  141. <td valign="top">url</td>
  142. <td valign="top">URL of the schema</td>
  143. <td align="center" valign="top">One of url or file is required</td>
  144. </tr>
  145. <tr>
  146. <td valign="top">file</td>
  147. <td valign="top">file of the schema</td>
  148. <td align="center" valign="top">One of url or file is required</td>
  149. </tr>
  150. </table>
  151. <h4>dtd</h4>
  152. <p>
  153. <tt>&lt;dtd&gt;</tt> is used to specify different locations for DTD resolution.
  154. </p>
  155. <table border="1" cellpadding="2" cellspacing="0">
  156. <tr>
  157. <td width="12%" valign="top"><b>Attribute</b></td>
  158. <td width="78%" valign="top"><b>Description</b></td>
  159. <td width="10%" valign="top"><b>Required</b></td>
  160. </tr>
  161. <tr>
  162. <td valign="top">publicId</td>
  163. <td valign="top">Public ID of the DTD to resolve</td>
  164. <td align="center" valign="top">Yes</td>
  165. </tr>
  166. <tr>
  167. <td valign="top">location</td>
  168. <td valign="top">Location of the DTD to use, which can be a file,
  169. a resource, or a URL</td>
  170. <td align="center" valign="top">Yes</td>
  171. </tr>
  172. </table>
  173. <h4>xmlcatalog</h4>
  174. <p>The <a href="../Types/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
  175. element is used to perform entity resolution.</p>
  176. <h4>attribute</h4>
  177. <p>The <tt>&lt;attribute&gt;</tt> element is used to set parser features.<br>
  178. Features usable with the xerces parser are defined here :
  179. <a href="http://xml.apache.org/xerces-j/features.html">Setting features</a><br>
  180. SAX features are defined here:
  181. <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a><br>
  182. </p>
  183. <table border="1" cellpadding="2" cellspacing="0">
  184. <tr>
  185. <td width="12%" valign="top"><b>Attribute</b></td>
  186. <td width="78%" valign="top"><b>Description</b></td>
  187. <td width="10%" valign="top"><b>Required</b></td>
  188. </tr>
  189. <tr>
  190. <td valign="top">name</td>
  191. <td valign="top">The name of the feature</td>
  192. <td align="center" valign="top">Yes</td>
  193. </tr>
  194. <tr>
  195. <td valign="top">value</td>
  196. <td valign="top">The boolean value of the feature</td>
  197. <td align="center" valign="top">Yes</td>
  198. </tr>
  199. </table>
  200. </p>
  201. <h4>property</h4>
  202. <p>The <tt>&lt;property&gt;</tt> element is used to set properties.
  203. These properties are defined here for the xerces XML parser implementation :
  204. <a href="http://xml.apache.org/xerces-j/properties.html">XML Parser properties</a>
  205. Properties can be used to set the schema used to validate the XML file.
  206. </p>
  207. <table border="1" cellpadding="2" cellspacing="0">
  208. <tr>
  209. <td width="12%" valign="top"><b>Attribute</b></td>
  210. <td width="78%" valign="top"><b>Description</b></td>
  211. <td width="10%" valign="top"><b>Required</b></td>
  212. </tr>
  213. <tr>
  214. <td valign="top">name</td>
  215. <td valign="top">The name of the feature</td>
  216. <td align="center" valign="top">Yes</td>
  217. </tr>
  218. <tr>
  219. <td valign="top">value</td>
  220. <td valign="top">The string value of the property</td>
  221. <td align="center" valign="top">Yes</td>
  222. </tr>
  223. </table>
  224. </p>
  225. <h3>Examples</h3>
  226. <pre>
  227. &lt;schemavalidate
  228. noNamespaceFile="document.xsd"
  229. file="xml/endpiece.xml"&gt;
  230. &lt;/schemavalidate&gt;
  231. </pre>
  232. Validate a document against an XML schema. The document does not declare
  233. any schema itself, which is why the <tt>noNamespaceFile</tt> is needed.
  234. <pre>
  235. &lt;presetdef name="validate-soap"&gt;
  236. &lt;schemavalidate &gt;
  237. &lt;schema namespace="http://schemas.xmlsoap.org/ws/2003/03/addressing"
  238. file="${soap.dir}/ws-addressing.xsd" /&gt;
  239. &lt;schema namespace="http://www.w3.org/2003/05/soap-envelope"
  240. file="${soap.dir}/soap12.xsd" /&gt;
  241. &lt;schema namespace="http://schemas.xmlsoap.org/wsdl/"
  242. file="${soap.dir}/wsdl.xsd" /&gt;
  243. &lt;schema namespace="http://www.w3.org/2001/XMLSchema"
  244. file="${soap.dir}/XMLSchema.xsd" /&gt;
  245. &lt;/schemavalidate&gt;
  246. &lt;/presetdef&gt;
  247. </pre>
  248. Declare a new preset task, <tt>&lt;validate-soap&gt;</tt>, that validates
  249. XSD and WSDL documents against the relevant specifications.
  250. To validate XSD documents, you also need XMLSchema.dtd and datatypes.dtd in
  251. the same directory as XMLSchema.xsd, or pointed to via the catalog. All
  252. these files can be fetched from <a href="http://www.w3.org/2001/XMLSchema">
  253. the W3C</a>.
  254. <pre>
  255. &lt;validate-soap file="xml/test.xsd"/&gt;
  256. </pre>
  257. Use the preset task defined above to validate an XML Schema document.
  258. <br>
  259. </body>
  260. </html>