xmlwf.xml 19 KB

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