Writing XML

XML documents can be hand-written using one of many editing tools now available. But the new uses to which XML markup is being put, including data interchange, increasingly require XML data to be generated automatically.

Outputting markup

Fortunately, getting software to write XML data is quite straightforward, and involves little more than including XML tags in the strings to be output:

PRINT #FileNum "<para>A paragraph.</para>"

fprintf(stdout, "<para>A paragraph.</para>\n");

System.out.println( "<para>A paragraph.</para>\n");

Clib.puts( "<para>A paragraph.</para>\n");

Escaping special characters

But it is very important to remember that some characters must be 'escaped' as entity references. Writing the '&', '<' or '>' characters ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.