XML serializer (OMXMLWRITE)

The OMXMLWRITE library can be used to convert a markup event stream to a well-formed XML instance. The library exports two functions, xml.writer and xml.written. Each function performs the same task through a different interface; which one is better to use depends on the context.

Example

The following program parses well-formed XML input and uses the OMXMLWRITE library to write it out as XML again.

  import "omxmlwrite.xmd" prefixed by xml.
  
  process
     do xml-parse scan #main-input
        output xml.written from #content
     done

This program can be used to normalize well-formed XML instances. All XML produced by the OMXMLWRITE library has the following properties:

  • it uses ASCII (or optionally UTF-8; see the documentation of xml.writer and xml.written for specifics) encoding only,
  • all elements with empty content are represented with an empty tag (unless configured otherwise; see the documentation of xml.writer and xml.written for specifics),
  • attributes are quoted using double quotes,
  • special characters < and & are represented using the built-in entities &lt; and &amp; whereas
  • unless using the optional UTF-8 mode, all other non-ASCII characters are represented as character entities with hexadecimal notation (&#x0a; for example).

Usage Note

To use OMXMLWRITE, you must import it into your program using an import declaration such as:

  import "omxmlwrite.xmd" prefixed by xml.