Any OmniMark veteran has probably written (or copied) the following OmniMark element rule hundreds of times:
element #implied output "<%q" repeat over specified attributes as a output " " || key of attribute a || "=%"" || attribute a || "%"" again output ">%c</%q>"
This simple rule attempts to reproduce the original markup in textual form. That is not exactly what it does, however. There are several corner cases which would make the output malformed.
An attribute value that contains quotes, ampersands, or less-than characters would lead to malformed start tags. For example,
<a text="He yelled "help"">
would become
<a text="He yelled "help"">
The original element content could contain ampersands or less-than characters which would also lead to malformed printout:
<a>3*a<b</a>
would be formatted as
<a>3*a<b</a>
There are other things that could go wrong:
Even if we take care to always produce well-formed markup and thus make its parsers happy with the result, humans can find it difficult to read. At this point, however, we're moving from the realm of serializing markup so it can be fed to a parser, to its pretty printing for human consumption. The rest of this article will discuss both tasks, covering XML and SGML in turn.