xmlwf.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <!--
  2. __ __ _
  3. ___\ \/ /_ __ __ _| |_
  4. / _ \\ /| '_ \ / _` | __|
  5. | __// \| |_) | (_| | |_
  6. \___/_/\_\ .__/ \__,_|\__|
  7. |_| XML parser
  8. Copyright (c) 2001 Scott Bronson <[email protected]>
  9. Copyright (c) 2002-2003 Fred L. Drake, Jr. <[email protected]>
  10. Copyright (c) 2009 Karl Waclawek <[email protected]>
  11. Copyright (c) 2016-2021 Sebastian Pipping <[email protected]>
  12. Copyright (c) 2016 Ardo van Rangelrooij <[email protected]>
  13. Copyright (c) 2017 Rhodri James <[email protected]>
  14. Copyright (c) 2020 Joe Orton <[email protected]>
  15. Copyright (c) 2021 Tim Bray <[email protected]>
  16. Unlike most of Expat,
  17. this file is copyrighted under the GNU Free Documentation License 1.1.
  18. -->
  19. <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  20. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  21. <!ENTITY dhfirstname "<firstname>Scott</firstname>">
  22. <!ENTITY dhsurname "<surname>Bronson</surname>">
  23. <!-- Please adjust the date whenever revising the manpage. -->
  24. <!ENTITY dhdate "<date>May 23, 2021</date>">
  25. <!ENTITY dhsection "<manvolnum>1</manvolnum>">
  26. <!ENTITY dhemail "<email>[email protected]</email>">
  27. <!ENTITY dhusername "Scott Bronson">
  28. <!ENTITY dhucpackage "<refentrytitle>XMLWF</refentrytitle>">
  29. <!ENTITY dhpackage "xmlwf">
  30. <!ENTITY debian "<productname>Debian GNU/Linux</productname>">
  31. <!ENTITY gnu "<acronym>GNU</acronym>">
  32. ]>
  33. <refentry>
  34. <refentryinfo>
  35. <address>
  36. &dhemail;
  37. </address>
  38. <author>
  39. &dhfirstname;
  40. &dhsurname;
  41. </author>
  42. <copyright>
  43. <year>2001</year>
  44. <holder>&dhusername;</holder>
  45. </copyright>
  46. &dhdate;
  47. </refentryinfo>
  48. <refmeta>
  49. &dhucpackage;
  50. &dhsection;
  51. </refmeta>
  52. <refnamediv>
  53. <refname>&dhpackage;</refname>
  54. <refpurpose>Determines if an XML document is well-formed</refpurpose>
  55. </refnamediv>
  56. <refsynopsisdiv>
  57. <cmdsynopsis>
  58. <command>&dhpackage;</command>
  59. <arg><replaceable>OPTIONS</replaceable></arg>
  60. <arg><replaceable>FILE</replaceable> ...</arg>
  61. </cmdsynopsis>
  62. <cmdsynopsis>
  63. <command>&dhpackage;</command>
  64. <arg choice="plain"><option>-h</option></arg>
  65. </cmdsynopsis>
  66. <cmdsynopsis>
  67. <command>&dhpackage;</command>
  68. <arg choice="plain"><option>-v</option></arg>
  69. </cmdsynopsis>
  70. </refsynopsisdiv>
  71. <refsect1>
  72. <title>DESCRIPTION</title>
  73. <para>
  74. <command>&dhpackage;</command> uses the Expat library to
  75. determine if an XML document is well-formed. It is
  76. non-validating.
  77. </para>
  78. <para>
  79. If you do not specify any files on the command-line, and you
  80. have a recent version of <command>&dhpackage;</command>, the
  81. input file will be read from standard input.
  82. </para>
  83. </refsect1>
  84. <refsect1>
  85. <title>WELL-FORMED DOCUMENTS</title>
  86. <para>
  87. A well-formed document must adhere to the
  88. following rules:
  89. </para>
  90. <itemizedlist>
  91. <listitem><para>
  92. The file begins with an XML declaration. For instance,
  93. <literal>&lt;?xml version="1.0" standalone="yes"?&gt;</literal>.
  94. <emphasis>NOTE</emphasis>:
  95. <command>&dhpackage;</command> does not currently
  96. check for a valid XML declaration.
  97. </para></listitem>
  98. <listitem><para>
  99. Every start tag is either empty (&lt;tag/&gt;)
  100. or has a corresponding end tag.
  101. </para></listitem>
  102. <listitem><para>
  103. There is exactly one root element. This element must contain
  104. all other elements in the document. Only comments, white
  105. space, and processing instructions may come after the close
  106. of the root element.
  107. </para></listitem>
  108. <listitem><para>
  109. All elements nest properly.
  110. </para></listitem>
  111. <listitem><para>
  112. All attribute values are enclosed in quotes (either single
  113. or double).
  114. </para></listitem>
  115. </itemizedlist>
  116. <para>
  117. If the document has a DTD, and it strictly complies with that
  118. DTD, then the document is also considered <emphasis>valid</emphasis>.
  119. <command>&dhpackage;</command> is a non-validating parser --
  120. it does not check the DTD. However, it does support
  121. external entities (see the <option>-x</option> option).
  122. </para>
  123. </refsect1>
  124. <refsect1>
  125. <title>OPTIONS</title>
  126. <para>
  127. When an option includes an argument, you may specify the argument either
  128. separately ("<option>-d</option> <replaceable>output</replaceable>") or concatenated with the
  129. option ("<option>-d</option><replaceable>output</replaceable>"). <command>&dhpackage;</command>
  130. supports both.
  131. </para>
  132. <variablelist>
  133. <varlistentry>
  134. <term><option>-a</option> <replaceable>factor</replaceable></term>
  135. <listitem>
  136. <para>
  137. Sets the maximum tolerated amplification factor
  138. for protection against billion laughs attacks (default: 100.0).
  139. The amplification factor is calculated as ..
  140. </para>
  141. <literallayout>
  142. amplification := (direct + indirect) / direct
  143. </literallayout>
  144. <para>
  145. .. while parsing, whereas
  146. &lt;direct&gt; is the number of bytes read
  147. from the primary document in parsing and
  148. &lt;indirect&gt; is the number of bytes
  149. added by expanding entities and reading of external DTD files,
  150. combined.
  151. </para>
  152. <para>
  153. <emphasis>NOTE</emphasis>:
  154. If you ever need to increase this value for non-attack payload,
  155. please file a bug report.
  156. </para>
  157. </listitem>
  158. </varlistentry>
  159. <varlistentry>
  160. <term><option>-b</option> <replaceable>bytes</replaceable></term>
  161. <listitem>
  162. <para>
  163. Sets the number of output bytes (including amplification)
  164. needed to activate protection against billion laughs attacks
  165. (default: 8 MiB).
  166. This can be thought of as an &quot;activation threshold&quot;.
  167. </para>
  168. <para>
  169. <emphasis>NOTE</emphasis>:
  170. If you ever need to increase this value for non-attack payload,
  171. please file a bug report.
  172. </para>
  173. </listitem>
  174. </varlistentry>
  175. <varlistentry>
  176. <term><option>-c</option></term>
  177. <listitem>
  178. <para>
  179. If the input file is well-formed and <command>&dhpackage;</command>
  180. doesn't encounter any errors, the input file is simply copied to
  181. the output directory unchanged.
  182. This implies no namespaces (turns off <option>-n</option>) and
  183. requires <option>-d</option> to specify an output directory.
  184. </para>
  185. </listitem>
  186. </varlistentry>
  187. <varlistentry>
  188. <term><option>-d</option> <replaceable>output-dir</replaceable></term>
  189. <listitem>
  190. <para>
  191. Specifies a directory to contain transformed
  192. representations of the input files.
  193. By default, <option>-d</option> outputs a canonical representation
  194. (described below).
  195. You can select different output formats using <option>-c</option>,
  196. <option>-m</option> and <option>-N</option>.
  197. </para>
  198. <para>
  199. The output filenames will
  200. be exactly the same as the input filenames or "STDIN" if the input is
  201. coming from standard input. Therefore, you must be careful that the
  202. output file does not go into the same directory as the input
  203. file. Otherwise, <command>&dhpackage;</command> will delete the
  204. input file before it generates the output file (just like running
  205. <literal>cat &lt; file &gt; file</literal> in most shells).
  206. </para>
  207. <para>
  208. Two structurally equivalent XML documents have a byte-for-byte
  209. identical canonical XML representation.
  210. Note that ignorable white space is considered significant and
  211. is treated equivalently to data.
  212. More on canonical XML can be found at
  213. http://www.jclark.com/xml/canonxml.html .
  214. </para>
  215. </listitem>
  216. </varlistentry>
  217. <varlistentry>
  218. <term><option>-e</option> <replaceable>encoding</replaceable></term>
  219. <listitem>
  220. <para>
  221. Specifies the character encoding for the document, overriding
  222. any document encoding declaration. <command>&dhpackage;</command>
  223. supports four built-in encodings:
  224. <literal>US-ASCII</literal>,
  225. <literal>UTF-8</literal>,
  226. <literal>UTF-16</literal>, and
  227. <literal>ISO-8859-1</literal>.
  228. Also see the <option>-w</option> option.
  229. </para>
  230. </listitem>
  231. </varlistentry>
  232. <varlistentry>
  233. <term><option>-k</option></term>
  234. <listitem>
  235. <para>
  236. When processing multiple files, <command>&dhpackage;</command>
  237. by default halts after the the first file with an error.
  238. This tells <command>&dhpackage;</command> to report the error
  239. but to keep processing.
  240. This can be useful, for example, when testing a filter that converts
  241. many files to XML and you want to quickly find out which conversions
  242. failed.
  243. </para>
  244. </listitem>
  245. </varlistentry>
  246. <varlistentry>
  247. <term><option>-m</option></term>
  248. <listitem>
  249. <para>
  250. Outputs some strange sort of XML file that completely
  251. describes the input file, including character positions.
  252. Requires <option>-d</option> to specify an output file.
  253. </para>
  254. </listitem>
  255. </varlistentry>
  256. <varlistentry>
  257. <term><option>-n</option></term>
  258. <listitem>
  259. <para>
  260. Turns on namespace processing. (describe namespaces)
  261. <option>-c</option> disables namespaces.
  262. </para>
  263. </listitem>
  264. </varlistentry>
  265. <varlistentry>
  266. <term><option>-N</option></term>
  267. <listitem>
  268. <para>
  269. Adds a doctype and notation declarations to canonical XML output.
  270. This matches the example output used by the formal XML test cases.
  271. Requires <option>-d</option> to specify an output file.
  272. </para>
  273. </listitem>
  274. </varlistentry>
  275. <varlistentry>
  276. <term><option>-p</option></term>
  277. <listitem>
  278. <para>
  279. Tells <command>&dhpackage;</command> to process external DTDs and parameter
  280. entities.
  281. </para>
  282. <para>
  283. Normally <command>&dhpackage;</command> never parses parameter
  284. entities. <option>-p</option> tells it to always parse them.
  285. <option>-p</option> implies <option>-x</option>.
  286. </para>
  287. </listitem>
  288. </varlistentry>
  289. <varlistentry>
  290. <term><option>-r</option></term>
  291. <listitem>
  292. <para>
  293. Normally <command>&dhpackage;</command> memory-maps the XML file
  294. before parsing; this can result in faster parsing on many
  295. platforms.
  296. <option>-r</option> turns off memory-mapping and uses normal file
  297. IO calls instead.
  298. Of course, memory-mapping is automatically turned off
  299. when reading from standard input.
  300. </para>
  301. <para>
  302. Use of memory-mapping can cause some platforms to report
  303. substantially higher memory usage for
  304. <command>&dhpackage;</command>, but this appears to be a matter of
  305. the operating system reporting memory in a strange way; there is
  306. not a leak in <command>&dhpackage;</command>.
  307. </para>
  308. </listitem>
  309. </varlistentry>
  310. <varlistentry>
  311. <term><option>-s</option></term>
  312. <listitem>
  313. <para>
  314. Prints an error if the document is not standalone.
  315. A document is standalone if it has no external subset and no
  316. references to parameter entities.
  317. </para>
  318. </listitem>
  319. </varlistentry>
  320. <varlistentry>
  321. <term><option>-t</option></term>
  322. <listitem>
  323. <para>
  324. Turns on timings. This tells Expat to parse the entire file,
  325. but not perform any processing.
  326. This gives a fairly accurate idea of the raw speed of Expat itself
  327. without client overhead.
  328. <option>-t</option> turns off most of the output options
  329. (<option>-d</option>, <option>-m</option>, <option>-c</option>, ...).
  330. </para>
  331. </listitem>
  332. </varlistentry>
  333. <varlistentry>
  334. <term><option>-v</option></term>
  335. <listitem>
  336. <para>
  337. Prints the version of the Expat library being used, including some
  338. information on the compile-time configuration of the library, and
  339. then exits.
  340. </para>
  341. </listitem>
  342. </varlistentry>
  343. <varlistentry>
  344. <term><option>-w</option></term>
  345. <listitem>
  346. <para>
  347. Enables support for Windows code pages.
  348. Normally, <command>&dhpackage;</command> will throw an error if it
  349. runs across an encoding that it is not equipped to handle itself. With
  350. <option>-w</option>, <command>&dhpackage;</command> will try to use a Windows code
  351. page. See also <option>-e</option>.
  352. </para>
  353. </listitem>
  354. </varlistentry>
  355. <varlistentry>
  356. <term><option>-x</option></term>
  357. <listitem>
  358. <para>
  359. Turns on parsing external entities.
  360. </para>
  361. <para>
  362. Non-validating parsers are not required to resolve external
  363. entities, or even expand entities at all.
  364. Expat always expands internal entities (?),
  365. but external entity parsing must be enabled explicitly.
  366. </para>
  367. <para>
  368. External entities are simply entities that obtain their
  369. data from outside the XML file currently being parsed.
  370. </para>
  371. <para>
  372. This is an example of an internal entity:
  373. <literallayout>
  374. &lt;!ENTITY vers '1.0.2'&gt;
  375. </literallayout>
  376. </para>
  377. <para>
  378. And here are some examples of external entities:
  379. <literallayout>
  380. &lt;!ENTITY header SYSTEM "header-&amp;vers;.xml"&gt; (parsed)
  381. &lt;!ENTITY logo SYSTEM "logo.png" PNG&gt; (unparsed)
  382. </literallayout>
  383. </para>
  384. </listitem>
  385. </varlistentry>
  386. <varlistentry>
  387. <term><option>--</option></term>
  388. <listitem>
  389. <para>
  390. (Two hyphens.)
  391. Terminates the list of options. This is only needed if a filename
  392. starts with a hyphen. For example:
  393. </para>
  394. <literallayout>
  395. &dhpackage; -- -myfile.xml
  396. </literallayout>
  397. <para>
  398. will run <command>&dhpackage;</command> on the file
  399. <filename>-myfile.xml</filename>.
  400. </para>
  401. </listitem>
  402. </varlistentry>
  403. </variablelist>
  404. <para>
  405. Older versions of <command>&dhpackage;</command> do not support
  406. reading from standard input.
  407. </para>
  408. </refsect1>
  409. <refsect1>
  410. <title>OUTPUT</title>
  411. <para>
  412. <command>&dhpackage;</command> outputs nothing for files which are problem-free.
  413. If any input file is not well-formed, or if the output for any
  414. input file cannot be opened, <command>&dhpackage;</command> prints a single
  415. line describing the problem to standard output.
  416. </para>
  417. <para>
  418. If the <option>-k</option> option is not provided, <command>&dhpackage;</command>
  419. halts upon encountering a well-formedness or output-file error.
  420. If <option>-k</option> is provided, <command>&dhpackage;</command> continues
  421. processing the remaining input files, describing problems found with any of them.
  422. </para>
  423. </refsect1>
  424. <refsect1>
  425. <title>EXIT STATUS</title>
  426. <para>For option <option>-v</option> or <option>-h</option>, <command>&dhpackage;</command> always exits with status code 0. For other cases, the following exit status codes are returned:
  427. <variablelist>
  428. <varlistentry>
  429. <term><option>0</option></term>
  430. <listitem><para>The input files are well-formed and the output (if requested) was written successfully.</para>
  431. </listitem>
  432. </varlistentry>
  433. <varlistentry>
  434. <term><option>1</option></term>
  435. <listitem><para>An internal error occurred.</para>
  436. </listitem>
  437. </varlistentry>
  438. <varlistentry>
  439. <term><option>2</option></term>
  440. <listitem><para>One or more input files were not well-formed or could not be parsed.</para>
  441. </listitem>
  442. </varlistentry>
  443. <varlistentry>
  444. <term><option>3</option></term>
  445. <listitem><para>If using the <option>-d</option> option, an error occurred opening an output file.</para>
  446. </listitem>
  447. </varlistentry>
  448. <varlistentry>
  449. <term><option>4</option></term>
  450. <listitem><para>There was a command-line argument error in how <command>&dhpackage;</command> was invoked.</para>
  451. </listitem>
  452. </varlistentry>
  453. </variablelist>
  454. </para>
  455. </refsect1>
  456. <refsect1>
  457. <title>BUGS</title>
  458. <para>
  459. The errors should go to standard error, not standard output.
  460. </para>
  461. <para>
  462. There should be a way to get <option>-d</option> to send its
  463. output to standard output rather than forcing the user to send
  464. it to a file.
  465. </para>
  466. <para>
  467. I have no idea why anyone would want to use the
  468. <option>-d</option>, <option>-c</option>, and
  469. <option>-m</option> options. If someone could explain it to
  470. me, I'd like to add this information to this manpage.
  471. </para>
  472. </refsect1>
  473. <refsect1>
  474. <title>SEE ALSO</title>
  475. <para>
  476. <literallayout>
  477. The Expat home page: https://libexpat.github.io/
  478. The W3 XML 1.0 specification (fourth edition): https://www.w3.org/TR/2006/REC-xml-20060816/
  479. Billion laughs attack: https://en.wikipedia.org/wiki/Billion_laughs_attack
  480. </literallayout>
  481. </para>
  482. </refsect1>
  483. <refsect1>
  484. <title>AUTHOR</title>
  485. <para>
  486. This manual page was originally written by &dhusername; &dhemail;
  487. in December 2001 for
  488. the &debian; system (but may be used by others). Permission is
  489. granted to copy, distribute and/or modify this document under
  490. the terms of the <acronym>GNU</acronym> Free Documentation
  491. License, Version 1.1.
  492. </para>
  493. </refsect1>
  494. </refentry>