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 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <html>
  2. <head>
  3. <title>SchemaValidate Task</title>
  4. </head>
  5. <body>
  6. <h2><a name="schemavalidate">SchemaValidate</a></h2>
  7. <h3>Description</h3>
  8. <p>This task validates XML files described by an XML Schema.
  9. The task extends the XmlValidate task with XSD-specific features.</p>
  10. <ol>
  11. <li>The parser is created validating and namespace aware
  12. </li>
  13. <li>Validation is turned on.</li>
  14. <li>and Schema validation is turned on.</li>
  15. <li>Any default schema supplied is used as the no-namespace schema
  16. <li>All nested schema declarations are turned into the list of namespace-url
  17. bindings for schema lookup.
  18. </ol>
  19. Note that nested catalogs are still used for lookup of the URLs given as the
  20. sources of schema documents, so you can still delegate lookup to a catalog, you
  21. just need to list all schema URIs and their URL equivalents.
  22. <p>This task supports the use of nested
  23. <li><a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a> elements</li>
  24. <li> <tt>&lt;schema&gt;</tt> elements, that bind a namespace URI to a URL or a
  25. local filename.
  26. <li><tt>&lt;dtd&gt;</tt> elements which are used to resolve DTDs and entities.</li>
  27. <li><tt>&lt;attribute&gt;</tt> elements which are used to set features on the parser.
  28. These can be any number of
  29. <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a>
  30. or other features that your parser may support.</li>
  31. <li><tt>&lt;property&gt;</tt> elements, containing string properties
  32. </p>
  33. <p>
  34. The task only supports SAX2 or later parsers: it is an error to specify a SAX1
  35. parser.
  36. <h3>Parameters</h3>
  37. <table border="1" cellpadding="2" cellspacing="0">
  38. <tr>
  39. <td valign="top"><b>Attribute</b></td>
  40. <td valign="top"><b>Description</b></td>
  41. <td align="center" valign="top"><b>Required</b></td>
  42. </tr>
  43. <tr>
  44. <td valign="top">file</td>
  45. <td valign="top">the file(s) you want to check. (optionally can use an embedded fileset)</td>
  46. <td valign="top" align="center">No</td>
  47. </tr>
  48. <tr>
  49. <td valign="top">defaultSchemaFile</td>
  50. <td valign="top">
  51. filename of a no-namespace XSD file to provide the
  52. schema for no-namespace XML content.
  53. </td>
  54. <td valign="top" align="center">No</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">noNamespaceURL</td>
  58. <td valign="top">
  59. URL of a no-namespace XSD file to provide the
  60. schema for no-namespace XML content.
  61. </td>
  62. <td valign="top" align="center">No</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">noNamespaceFile</td>
  66. <td valign="top">
  67. filename of a no-namespace XSD file to provide the
  68. schema for no-namespace XML content.
  69. </td>
  70. <td valign="top" align="center">No</td>
  71. </tr>
  72. <tr>
  73. <td valign="top">fullchecking</td>
  74. <td valign="top">
  75. enable full schema checking. Slow but strict.
  76. </td>
  77. <td valign="top" align="center">No - default true</td>
  78. </tr>
  79. <tr>
  80. <td valign="top">lenient</td>
  81. <td valign="top">
  82. if true, only check the XML document is well formed
  83. </td>
  84. <td valign="top" align="center">No</td>
  85. </tr>
  86. <tr>
  87. <td valign="top">classname</td>
  88. <td valign="top">the parser to use.</td>
  89. <td align="center" valign="top">No</td>
  90. </tr>
  91. <tr>
  92. <td valign="top">classpathref</td>
  93. <td valign="top">where to find the parser class.
  94. Optionally can use an embedded <tt>&lt;classpath&gt;</tt> element.</td>
  95. <td align="center" valign="top">No</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">failonerror</td>
  99. <td valign="top">fails on a error if set to true (defaults to true).</td>
  100. <td align="center" valign="top">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">warn</td>
  104. <td valign="top">log parser warn events.</td>
  105. <td align="center" valign="top">No</td>
  106. </tr>
  107. </table>
  108. <h3><a name="nested">Nested Elements</a></h3>
  109. <h4>schema</h4>
  110. <p>
  111. Identify the name and location of a schema that may be used in validating
  112. the document(s).
  113. </p>
  114. <table border="1" cellpadding="2" cellspacing="0">
  115. <tr>
  116. <td width="12%" valign="top"><b>Attribute</b></td>
  117. <td width="78%" valign="top"><b>Description</b></td>
  118. <td width="10%" valign="top"><b>Required</b></td>
  119. </tr>
  120. <tr>
  121. <td valign="top">namespace</td>
  122. <td valign="top">URI of the schema namespace</td>
  123. <td align="center" valign="top">Yes</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">url</td>
  127. <td valign="top">URL of the schema</td>
  128. <td align="center" valign="top">One of url or file is required</td>
  129. </tr>
  130. <tr>
  131. <td valign="top">file</td>
  132. <td valign="top">file of the schema</td>
  133. <td align="center" valign="top">One of url or file is required</td>
  134. </tr>
  135. </table>
  136. <h4>dtd</h4>
  137. <p>
  138. <tt>&lt;dtd&gt;</tt> is used to specify different locations for DTD resolution.
  139. </p>
  140. <table border="1" cellpadding="2" cellspacing="0">
  141. <tr>
  142. <td width="12%" valign="top"><b>Attribute</b></td>
  143. <td width="78%" valign="top"><b>Description</b></td>
  144. <td width="10%" valign="top"><b>Required</b></td>
  145. </tr>
  146. <tr>
  147. <td valign="top">publicId</td>
  148. <td valign="top">Public ID of the DTD to resolve</td>
  149. <td align="center" valign="top">Yes</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">location</td>
  153. <td valign="top">Location of the DTD to use, which can be a file,
  154. a resource, or a URL</td>
  155. <td align="center" valign="top">Yes</td>
  156. </tr>
  157. </table>
  158. <h4>xmlcatalog</h4>
  159. <p>The <a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
  160. element is used to perform entity resolution.</p>
  161. <h4>attribute</h4>
  162. <p>The <tt>&lt;attribute&gt;</tt> element is used to set parser features.<br>
  163. Features usable with the xerces parser are defined here :
  164. <a href="http://xml.apache.org/xerces-j/features.html">Setting features</a><br>
  165. SAX features are defined here:
  166. <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a><br>
  167. </p>
  168. <table border="1" cellpadding="2" cellspacing="0">
  169. <tr>
  170. <td width="12%" valign="top"><b>Attribute</b></td>
  171. <td width="78%" valign="top"><b>Description</b></td>
  172. <td width="10%" valign="top"><b>Required</b></td>
  173. </tr>
  174. <tr>
  175. <td valign="top">name</td>
  176. <td valign="top">The name of the feature</td>
  177. <td align="center" valign="top">Yes</td>
  178. </tr>
  179. <tr>
  180. <td valign="top">value</td>
  181. <td valign="top">The boolean value of the feature</td>
  182. <td align="center" valign="top">Yes</td>
  183. </tr>
  184. </table>
  185. </p>
  186. <h4>property</h4>
  187. <p>The <tt>&lt;property&gt;</tt> element is used to set properties.
  188. These properties are defined here for the xerces XML parser implementation :
  189. <a href="http://xml.apache.org/xerces-j/properties.html">XML Parser properties</a>
  190. Properties can be used to set the schema used to validate the XML file.
  191. </p>
  192. <table border="1" cellpadding="2" cellspacing="0">
  193. <tr>
  194. <td width="12%" valign="top"><b>Attribute</b></td>
  195. <td width="78%" valign="top"><b>Description</b></td>
  196. <td width="10%" valign="top"><b>Required</b></td>
  197. </tr>
  198. <tr>
  199. <td valign="top">name</td>
  200. <td valign="top">The name of the feature</td>
  201. <td align="center" valign="top">Yes</td>
  202. </tr>
  203. <tr>
  204. <td valign="top">value</td>
  205. <td valign="top">The string value of the property</td>
  206. <td align="center" valign="top">Yes</td>
  207. </tr>
  208. </table>
  209. </p>
  210. <h3>Examples</h3>
  211. <pre>
  212. &lt;xmlvalidate file="toto.xml"/&gt;
  213. </pre>
  214. Validate toto.xml
  215. <pre>
  216. &lt;xmlvalidate failonerror="no" lenient="yes" warn="yes"
  217. classname="org.apache.xerces.parsers.SAXParser"&gt;
  218. classpath="lib/xerces.jar"&gt;
  219. &lt;fileset dir="src" includes="style/*.xsl"/&gt;
  220. &lt;/xmlvalidate&gt;
  221. </pre>
  222. Validate all .xsl files in src/style, but only warn if there is an error, rather than
  223. halt the build.
  224. <pre>
  225. &lt;xmlvalidate file="struts-config.xml" warn="false"&gt;
  226. &lt;dtd publicId="-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
  227. location="struts-config_1_0.dtd"/&gt;
  228. &lt;/xmlvalidate&gt;
  229. </pre>
  230. Validate a struts configuration, using a local copy of the DTD.
  231. <pre>
  232. &lt;xmlvalidate failonerror="no"&gt;
  233. &lt;fileset dir="${project.dir}" includes="**/*.xml"/&gt;
  234. &lt;xmlcatalog refid="mycatalog"/&gt;
  235. &lt;/xmlvalidate&gt;
  236. </pre>
  237. Scan all XML files in the project, using a predefined catalog to map URIs to local files.
  238. <pre>
  239. &lt;xmlvalidate failonerror="no"&gt;
  240. &lt;fileset dir="${project.dir}" includes="**/*.xml"/&gt;
  241. &lt;xmlcatalog&gt;
  242. &lt;dtd
  243. publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
  244. location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
  245. &lt;/xmlcatalog&gt;
  246. &lt;/xmlvalidate&gt;
  247. </pre>
  248. Scan all XML files in the project, using the catalog defined inline.
  249. <pre>
  250. &lt;xmlvalidate failonerror="yes" lenient="no" warn="yes"&gt;
  251. &lt;fileset dir="xml" includes="**/*.xml"/&gt;
  252. &lt;attribute name="http://xml.org/sax/features/validation" value="true"/&gt;
  253. &lt;attribute name="http://apache.org/xml/features/validation/schema" value="true"/&gt;
  254. &lt;attribute name="http://xml.org/sax/features/namespaces" value="true"/&gt;
  255. &lt;/xmlvalidate&gt;
  256. </pre>
  257. Validate all .xml files in xml directory with the parser configured to perform schema validation. Note: The parser must support the
  258. <pre>http://apache.org/xml/features/validation/schema</pre> feature.
  259. <br>
  260. <pre>
  261. <!-- Converts path to URL format -->
  262. &lt;pathconvert dirsep="/" property="xsd.file"&gt;
  263. &lt;path&gt;
  264. &lt;pathelement location="xml/doc.xsd"/&gt;
  265. &lt;/path&gt;
  266. &lt;/pathconvert&gt;
  267. &lt;xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false"
  268. failonerror="true" warn="true"&gt;
  269. &lt;attribute name="http://apache.org/xml/features/validation/schema"
  270. value="true"/&gt;
  271. &lt;attribute name="http://xml.org/sax/features/namespaces" value="true"/&gt;
  272. &lt;property
  273. name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
  274. value="${xsd.file}"/&gt;
  275. &lt;/xmlvalidate&gt;
  276. </pre>
  277. <br>
  278. Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd.
  279. <br>
  280. <hr>
  281. <p align="center">Copyright &copy; 2001-2002,2004 The Apache Software Foundation. All rights
  282. Reserved.</p>
  283. </body>
  284. </html>