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.

xmlvalidate.html 5.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <html>
  2. <head>
  3. <title>XMLValidate Task</title>
  4. </head>
  5. <body>
  6. <h2><a name="xmlvalidate">XMLValidate</a></h2>
  7. <h3>Description</h3>
  8. <p>This task checks xml files are valid (or only well formed). The
  9. task uses the SAX2 parser implementation provided by JAXP by default
  10. (probably the one that is used by Ant itself), but one can specify any
  11. SAX1/2 parser if needed.</p>
  12. <p>This task supports the use of nested
  13. <li/><a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a> elements
  14. <li/><tt>&lt;dtd&gt;</tt> elements which are used to resolve DTDs and entities.
  15. <li/><tt>&lt;attribute&gt;</tt> elements which are used to set features on the parser. These can be any number of <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description">http://xml.org/sax/features/</a> or other features that your parser may support.
  16. </p>
  17. <h3>Parameters</h3>
  18. <table border="1" cellpadding="2" cellspacing="0">
  19. <tr>
  20. <td valign="top"><b>Attribute</b></td>
  21. <td valign="top"><b>Description</b></td>
  22. <td align="center" valign="top"><b>Required</b></td>
  23. </tr>
  24. <tr>
  25. <td valign="top">file</td>
  26. <td valign="top">the file(s) you want to check. (optionally can use an embedded fileset)</td>
  27. <td valign="top" align="center">No</td>
  28. </tr>
  29. <tr>
  30. <td valign="top">lenient</td>
  31. <td valign="top">
  32. if true, only check the xml document is well formed
  33. (ignored if the specified parser is as SAX1 parser)
  34. </td>
  35. <td valign="top" align="center">No</td>
  36. </tr>
  37. <tr>
  38. <td valign="top">classname</td>
  39. <td valign="top">the parser to use.</td>
  40. <td align="center" valign="top">No</td>
  41. </tr>
  42. <tr>
  43. <td valign="top">classpathref</td>
  44. <td valign="top">where to find the parser class. Optionally can use an embedded classpath element.</td>
  45. <td align="center" valign="top">No</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">failonerror</td>
  49. <td valign="top">fails on a error if set to true (defaults to true).</td>
  50. <td align="center" valign="top">No</td>
  51. </tr>
  52. <tr>
  53. <td valign="top">warn</td>
  54. <td valign="top">log parser warn events.</td>
  55. <td align="center" valign="top">No</td>
  56. </tr>
  57. </table>
  58. <h3><a name="nested">Nested Elements</a></h3>
  59. <h4>dtd</h4>
  60. &lt;dtd&gt; is used to specify different locations for DTD resolution.
  61. <table border="1" cellpadding="2" cellspacing="0">
  62. <tr>
  63. <td width="12%" valign="top"><b>Attribute</b></td>
  64. <td width="78%" valign="top"><b>Description</b></td>
  65. <td width="10%" valign="top"><b>Required</b></td>
  66. </tr>
  67. <tr>
  68. <td valign="top">publicId</td>
  69. <td valign="top">Public ID of the DTD to resolve</td>
  70. <td align="center" valign="top">Yes</td>
  71. </tr>
  72. <tr>
  73. <td valign="top">location</td>
  74. <td valign="top">Location of the DTD to use, which can be a file,
  75. a resource, or a URL</td>
  76. <td align="center" valign="top">Yes</td>
  77. </tr>
  78. </table>
  79. <h4>xmlcatalog</h4>
  80. <p>The <a href="../CoreTypes/xmlcatalog.html">xmlcatalog</a>
  81. element is used to perform Entity resolution.</p>
  82. <h4>attribute</h4>
  83. <p>The attribute element is used to set SAX Parser features.
  84. There can an arbitrary amount of attribute set as defined here:
  85. <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description">http://xml.org/sax/features/</a>
  86. A feature essentialy changes the mode of the parser.
  87. &lt;attribute&gt; an attribute is used to set specific features on the parser.
  88. <table border="1" cellpadding="2" cellspacing="0">
  89. <tr>
  90. <td width="12%" valign="top"><b>Attribute</b></td>
  91. <td width="78%" valign="top"><b>Description</b></td>
  92. <td width="10%" valign="top"><b>Required</b></td>
  93. </tr>
  94. <tr>
  95. <td valign="top">name</td>
  96. <td valign="top">The name of the feature</td>
  97. <td align="center" valign="top">Yes</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">value</td>
  101. <td valign="top">The boolean value of the feature</td>
  102. <td align="center" valign="top">Yes</td>
  103. </tr>
  104. </table>
  105. </p>
  106. <h3>Examples</h3>
  107. <pre>
  108. &lt;xmlvalidate file="toto.xml"/&gt;
  109. </pre>
  110. Validate toto.xml
  111. <pre>
  112. &lt;xmlvalidate failonerror="no" lenient="yes" warn="yes"
  113. classname="org.apache.xerces.parsers.SAXParser"&gt;
  114. classpath="lib/xerces.jar"&gt;
  115. &lt;fileset dir="src" includes="style/*.xsl"/&gt;
  116. &lt;/xmlvalidate&gt;
  117. </pre>
  118. Validate all .xsl files in src/style, but only warn if there is an error, rather than
  119. halt the build.
  120. <pre>
  121. &lt;xmlvalidate file="struts-config.xml" warn="false"&gt;
  122. &lt;dtd publicId="-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
  123. location="struts-config_1_0.dtd"/&gt;
  124. &lt;/xmlvalidate&gt;
  125. </pre>
  126. Validate a struts configuration, using a local copy of the DTD.
  127. <pre>
  128. &lt;xmlvalidate failonerror="no"&gt;
  129. &lt;fileset dir="${project.dir}" includes="**/*.xml"/&gt;
  130. &lt;xmlcatalog refid="mycatalog"/&gt;
  131. &lt;/xmlvalidate&gt;
  132. </pre>
  133. Scan all XML files in the project, using a predefined catalog to map URIs to local files.
  134. <pre>
  135. &lt;xmlvalidate failonerror="no"&gt;
  136. &lt;fileset dir="${project.dir}" includes="**/*.xml"/&gt;
  137. &lt;xmlcatalog&gt;
  138. &lt;dtd
  139. publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
  140. location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
  141. &lt;/xmlcatalog&gt;
  142. &lt;/xmlvalidate&gt;
  143. </pre>
  144. Scan all XML files in the project, using the catalog defined inline.
  145. <pre>
  146. &lt;xmlvalidate failonerror="yes" lenient="no" warn="yes"&gt;
  147. &lt;fileset dir="xml" includes="**/*.xml"/&gt;
  148. &lt;attribute name="http://xml.org/sax/features/validation" value="true"/&gt;
  149. &lt;attribute name="http://apache.org/xml/features/validation/schema" value="true"/&gt;
  150. &lt;/xmlvalidate&gt;
  151. </pre>
  152. Validate all .xml files in xml directory with the parser configured to perform schema validation. Note: The parser must support the <pre>http://apache.org/xml/features/validation/schema</pre> feature.
  153. <br>
  154. <hr>
  155. <p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
  156. Reserved.</p>
  157. </body>
  158. </html>