Table of Contents
In the previous section, we have shown how to parse an existing XML document by
programming. It is also important to see how an XML document can be created by
programming. We will therefore show the inverse of the programs shown
previously by writing a program that parses the compact form we
produced and expand it into the corresponding XML document. In principle, after
compaction and expansion, we should recover the original XML document with which we
started but since we have not faithfully transformed whitespace, the files are not strictly
identical. Although one can write a program to create a file with XML tags and their
content using print
methods, we will show (Section 9.1)
that it is both simpler and more systematic to create an XML document in memory using
the DOM model, to modify it and then to print it using a serializer. In Section 9.2, we will describe how to create an XML document by
parsing a text file and send SAX events to a transformer and in Section 9.3
we will show how to do the same with the StAX streaming approach.