xmlwf.xml 19 KB

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