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.3 kB

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