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

The following example program parses well-formed SGML input and uses the OMSGMLWRITE library to write it out as SGML again.

  import "omsgmlwrite.xmd" prefixed by sgml.
     do sgml-parse document scan #main-input
        output sgml.written from #content

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

  • attributes are quoted using double quotes,
  • double quotes inside attributes are escaped as character entities ",
  • declared cdata and sdata entities are represented as entity references, and
  • characters < and & in data content are followed by the empty markup declaration <!>,
  • all non-ASCII characters are represented either using the UTF-8 encoding or as character entities (&#10; for example).