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.8 KiB

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