xmlwf.1 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. '\" -*- coding: us-ascii -*-
  2. .if \n(.g .ds T< \\FC
  3. .if \n(.g .ds T> \\F[\n[.fam]]
  4. .de URL
  5. \\$2 \(la\\$1\(ra\\$3
  6. ..
  7. .if \n(.g .mso www.tmac
  8. .TH XMLWF 1 "September 24, 2025" "" ""
  9. .SH NAME
  10. xmlwf \- Determines if an XML document is well-formed
  11. .SH SYNOPSIS
  12. 'nh
  13. .fi
  14. .ad l
  15. \fBxmlwf\fR \kx
  16. .if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
  17. 'in \n(.iu+\nxu
  18. [\fIOPTIONS\fR] [\fIFILE\fR ...]
  19. 'in \n(.iu-\nxu
  20. .ad b
  21. 'hy
  22. 'nh
  23. .fi
  24. .ad l
  25. \fBxmlwf\fR \kx
  26. .if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
  27. 'in \n(.iu+\nxu
  28. \fB-h\fR | \fB--help\fR
  29. 'in \n(.iu-\nxu
  30. .ad b
  31. 'hy
  32. 'nh
  33. .fi
  34. .ad l
  35. \fBxmlwf\fR \kx
  36. .if (\nx>(\n(.l/2)) .nr x (\n(.l/5)
  37. 'in \n(.iu+\nxu
  38. \fB-v\fR | \fB--version\fR
  39. 'in \n(.iu-\nxu
  40. .ad b
  41. 'hy
  42. .SH DESCRIPTION
  43. \fBxmlwf\fR uses the Expat library to
  44. determine if an XML document is well-formed. It is
  45. non-validating.
  46. .PP
  47. If you do not specify any files on the command-line, and you
  48. have a recent version of \fBxmlwf\fR, the
  49. input file will be read from standard input.
  50. .SH "WELL-FORMED DOCUMENTS"
  51. A well-formed document must adhere to the
  52. following rules:
  53. .TP 0.2i
  54. \(bu
  55. The file begins with an XML declaration. For instance,
  56. \*(T<<?xml version="1.0" standalone="yes"?>\*(T>.
  57. \fINOTE\fR:
  58. \fBxmlwf\fR does not currently
  59. check for a valid XML declaration.
  60. .TP 0.2i
  61. \(bu
  62. Every start tag is either empty (<tag/>)
  63. or has a corresponding end tag.
  64. .TP 0.2i
  65. \(bu
  66. There is exactly one root element. This element must contain
  67. all other elements in the document. Only comments, white
  68. space, and processing instructions may come after the close
  69. of the root element.
  70. .TP 0.2i
  71. \(bu
  72. All elements nest properly.
  73. .TP 0.2i
  74. \(bu
  75. All attribute values are enclosed in quotes (either single
  76. or double).
  77. .PP
  78. If the document has a DTD, and it strictly complies with that
  79. DTD, then the document is also considered \fIvalid\fR.
  80. \fBxmlwf\fR is a non-validating parser --
  81. it does not check the DTD. However, it does support
  82. external entities (see the \*(T<\fB\-x\fR\*(T> option).
  83. .SH OPTIONS
  84. When an option includes an argument, you may specify the argument either
  85. separately ("\*(T<\fB\-d\fR\*(T> \fIoutput\fR") or concatenated with the
  86. option ("\*(T<\fB\-d\fR\*(T>\fIoutput\fR"). \fBxmlwf\fR
  87. supports both.
  88. .TP
  89. \*(T<\fB\-a\fR\*(T> \fIfactor\fR
  90. Sets the maximum tolerated amplification factor
  91. for protection against amplification attacks
  92. like the billion laughs attack
  93. (default: 100.0
  94. for the sum of direct and indirect output and also
  95. for allocations of dynamic memory).
  96. The amplification factor is calculated as ..
  97. .nf
  98. amplification := (direct + indirect) / direct
  99. .fi
  100. \&.. with regard to use of entities and ..
  101. .nf
  102. amplification := allocated / direct
  103. .fi
  104. \&.. with regard to dynamic memory while parsing.
  105. <direct> is the number of bytes read
  106. from the primary document in parsing,
  107. <indirect> is the number of bytes
  108. added by expanding entities and reading of external DTD files,
  109. combined, and
  110. <allocated> is the total number of bytes of dynamic memory
  111. allocated (and not freed) per hierarchy of parsers.
  112. \fINOTE\fR:
  113. If you ever need to increase this value for non-attack payload,
  114. please file a bug report.
  115. .TP
  116. \*(T<\fB\-b\fR\*(T> \fIbytes\fR
  117. Sets the number of output bytes (including amplification)
  118. needed to activate protection against amplification attacks
  119. like billion laughs
  120. (default: 8 MiB for the sum of direct and indirect output,
  121. and 64 MiB for allocations of dynamic memory).
  122. This can be thought of as an "activation threshold".
  123. \fINOTE\fR:
  124. If you ever need to increase this value for non-attack payload,
  125. please file a bug report.
  126. .TP
  127. \*(T<\fB\-c\fR\*(T>
  128. If the input file is well-formed and \fBxmlwf\fR
  129. doesn't encounter any errors, the input file is simply copied to
  130. the output directory unchanged.
  131. This implies no namespaces (turns off \*(T<\fB\-n\fR\*(T>) and
  132. requires \*(T<\fB\-d\fR\*(T> to specify an output directory.
  133. .TP
  134. \*(T<\fB\-d\fR\*(T> \fIoutput-dir\fR
  135. Specifies a directory to contain transformed
  136. representations of the input files.
  137. By default, \*(T<\fB\-d\fR\*(T> outputs a canonical representation
  138. (described below).
  139. You can select different output formats using \*(T<\fB\-c\fR\*(T>,
  140. \*(T<\fB\-m\fR\*(T> and \*(T<\fB\-N\fR\*(T>.
  141. The output filenames will
  142. be exactly the same as the input filenames or "STDIN" if the input is
  143. coming from standard input. Therefore, you must be careful that the
  144. output file does not go into the same directory as the input
  145. file. Otherwise, \fBxmlwf\fR will delete the
  146. input file before it generates the output file (just like running
  147. \*(T<cat < file > file\*(T> in most shells).
  148. Two structurally equivalent XML documents have a byte-for-byte
  149. identical canonical XML representation.
  150. Note that ignorable white space is considered significant and
  151. is treated equivalently to data.
  152. More on canonical XML can be found at
  153. http://www.jclark.com/xml/canonxml.html .
  154. .TP
  155. \*(T<\fB\-e\fR\*(T> \fIencoding\fR
  156. Specifies the character encoding for the document, overriding
  157. any document encoding declaration. \fBxmlwf\fR
  158. supports four built-in encodings:
  159. \*(T<US\-ASCII\*(T>,
  160. \*(T<UTF\-8\*(T>,
  161. \*(T<UTF\-16\*(T>, and
  162. \*(T<ISO\-8859\-1\*(T>.
  163. Also see the \*(T<\fB\-w\fR\*(T> option.
  164. .TP
  165. \*(T<\fB\-g\fR\*(T> \fIbytes\fR
  166. Sets the buffer size to request per call pair to
  167. \*(T<\fBXML_GetBuffer\fR\*(T> and \*(T<\fBread\fR\*(T>
  168. (default: 8 KiB).
  169. .TP
  170. \*(T<\fB\-h\fR\*(T>, \*(T<\fB\-\-help\fR\*(T>
  171. Prints short usage information on command \fBxmlwf\fR,
  172. and then exits.
  173. Similar to this man page but more concise.
  174. .TP
  175. \*(T<\fB\-k\fR\*(T>
  176. When processing multiple files, \fBxmlwf\fR
  177. by default halts after the the first file with an error.
  178. This tells \fBxmlwf\fR to report the error
  179. but to keep processing.
  180. This can be useful, for example, when testing a filter that converts
  181. many files to XML and you want to quickly find out which conversions
  182. failed.
  183. .TP
  184. \*(T<\fB\-m\fR\*(T>
  185. Outputs some strange sort of XML file that completely
  186. describes the input file, including character positions.
  187. Requires \*(T<\fB\-d\fR\*(T> to specify an output file.
  188. .TP
  189. \*(T<\fB\-n\fR\*(T>
  190. Turns on namespace processing. (describe namespaces)
  191. \*(T<\fB\-c\fR\*(T> disables namespaces.
  192. .TP
  193. \*(T<\fB\-N\fR\*(T>
  194. Adds a doctype and notation declarations to canonical XML output.
  195. This matches the example output used by the formal XML test cases.
  196. Requires \*(T<\fB\-d\fR\*(T> to specify an output file.
  197. .TP
  198. \*(T<\fB\-p\fR\*(T>
  199. Tells \fBxmlwf\fR to process external DTDs and parameter
  200. entities.
  201. Normally \fBxmlwf\fR never parses parameter
  202. entities. \*(T<\fB\-p\fR\*(T> tells it to always parse them.
  203. \*(T<\fB\-p\fR\*(T> implies \*(T<\fB\-x\fR\*(T>.
  204. .TP
  205. \*(T<\fB\-q\fR\*(T>
  206. Disable reparse deferral, and allow quadratic parse runtime
  207. on large tokens (default: reparse deferral enabled).
  208. .TP
  209. \*(T<\fB\-r\fR\*(T>
  210. Normally \fBxmlwf\fR memory-maps the XML file
  211. before parsing; this can result in faster parsing on many
  212. platforms.
  213. \*(T<\fB\-r\fR\*(T> turns off memory-mapping and uses normal file
  214. IO calls instead.
  215. Of course, memory-mapping is automatically turned off
  216. when reading from standard input.
  217. Use of memory-mapping can cause some platforms to report
  218. substantially higher memory usage for
  219. \fBxmlwf\fR, but this appears to be a matter of
  220. the operating system reporting memory in a strange way; there is
  221. not a leak in \fBxmlwf\fR.
  222. .TP
  223. \*(T<\fB\-s\fR\*(T>
  224. Prints an error if the document is not standalone.
  225. A document is standalone if it has no external subset and no
  226. references to parameter entities.
  227. .TP
  228. \*(T<\fB\-t\fR\*(T>
  229. Turns on timings. This tells Expat to parse the entire file,
  230. but not perform any processing.
  231. This gives a fairly accurate idea of the raw speed of Expat itself
  232. without client overhead.
  233. \*(T<\fB\-t\fR\*(T> turns off most of the output options
  234. (\*(T<\fB\-d\fR\*(T>, \*(T<\fB\-m\fR\*(T>, \*(T<\fB\-c\fR\*(T>, ...).
  235. .TP
  236. \*(T<\fB\-v\fR\*(T>, \*(T<\fB\-\-version\fR\*(T>
  237. Prints the version of the Expat library being used, including some
  238. information on the compile-time configuration of the library, and
  239. then exits.
  240. .TP
  241. \*(T<\fB\-w\fR\*(T>
  242. Enables support for Windows code pages.
  243. Normally, \fBxmlwf\fR will throw an error if it
  244. runs across an encoding that it is not equipped to handle itself. With
  245. \*(T<\fB\-w\fR\*(T>, \fBxmlwf\fR will try to use a Windows code
  246. page. See also \*(T<\fB\-e\fR\*(T>.
  247. .TP
  248. \*(T<\fB\-x\fR\*(T>
  249. Turns on parsing external entities.
  250. Non-validating parsers are not required to resolve external
  251. entities, or even expand entities at all.
  252. Expat always expands internal entities (?),
  253. but external entity parsing must be enabled explicitly.
  254. External entities are simply entities that obtain their
  255. data from outside the XML file currently being parsed.
  256. This is an example of an internal entity:
  257. .nf
  258. <!ENTITY vers '1.0.2'>
  259. .fi
  260. And here are some examples of external entities:
  261. .nf
  262. <!ENTITY header SYSTEM "header\-&vers;.xml"> (parsed)
  263. <!ENTITY logo SYSTEM "logo.png" PNG> (unparsed)
  264. .fi
  265. .TP
  266. \*(T<\fB\-\-\fR\*(T>
  267. (Two hyphens.)
  268. Terminates the list of options. This is only needed if a filename
  269. starts with a hyphen. For example:
  270. .nf
  271. xmlwf \-\- \-myfile.xml
  272. .fi
  273. will run \fBxmlwf\fR on the file
  274. \*(T<\fI\-myfile.xml\fR\*(T>.
  275. .PP
  276. Older versions of \fBxmlwf\fR do not support
  277. reading from standard input.
  278. .SH OUTPUT
  279. \fBxmlwf\fR outputs nothing for files which are problem-free.
  280. If any input file is not well-formed, or if the output for any
  281. input file cannot be opened, \fBxmlwf\fR prints a single
  282. line describing the problem to standard output.
  283. .PP
  284. If the \*(T<\fB\-k\fR\*(T> option is not provided, \fBxmlwf\fR
  285. halts upon encountering a well-formedness or output-file error.
  286. If \*(T<\fB\-k\fR\*(T> is provided, \fBxmlwf\fR continues
  287. processing the remaining input files, describing problems found with any of them.
  288. .SH "EXIT STATUS"
  289. For options \*(T<\fB\-v\fR\*(T>|\*(T<\fB\-\-version\fR\*(T> or \*(T<\fB\-h\fR\*(T>|\*(T<\fB\-\-help\fR\*(T>, \fBxmlwf\fR always exits with status code 0. For other cases, the following exit status codes are returned:
  290. .TP
  291. \*(T<\fB0\fR\*(T>
  292. The input files are well-formed and the output (if requested) was written successfully.
  293. .TP
  294. \*(T<\fB1\fR\*(T>
  295. An internal error occurred.
  296. .TP
  297. \*(T<\fB2\fR\*(T>
  298. One or more input files were not well-formed or could not be parsed.
  299. .TP
  300. \*(T<\fB3\fR\*(T>
  301. If using the \*(T<\fB\-d\fR\*(T> option, an error occurred opening an output file.
  302. .TP
  303. \*(T<\fB4\fR\*(T>
  304. There was a command-line argument error in how \fBxmlwf\fR was invoked.
  305. .SH BUGS
  306. The errors should go to standard error, not standard output.
  307. .PP
  308. There should be a way to get \*(T<\fB\-d\fR\*(T> to send its
  309. output to standard output rather than forcing the user to send
  310. it to a file.
  311. .PP
  312. I have no idea why anyone would want to use the
  313. \*(T<\fB\-d\fR\*(T>, \*(T<\fB\-c\fR\*(T>, and
  314. \*(T<\fB\-m\fR\*(T> options. If someone could explain it to
  315. me, I'd like to add this information to this manpage.
  316. .SH "SEE ALSO"
  317. .nf
  318. The Expat home page: https://libexpat.github.io/
  319. The W3 XML 1.0 specification (fourth edition): https://www.w3.org/TR/2006/REC\-xml\-20060816/
  320. Billion laughs attack: https://en.wikipedia.org/wiki/Billion_laughs_attack
  321. .fi
  322. .SH AUTHOR
  323. This manual page was originally written by Scott Bronson <\*(T<[email protected]\*(T>>
  324. in December 2001 for
  325. the Debian GNU/Linux system (but may be used by others). Permission is
  326. granted to copy, distribute and/or modify this document under
  327. the terms of the GNU Free Documentation
  328. License, Version 1.1.