Java Reference
In-Depth Information
LISTING 19.4
Continued
47: channel.appendChild(item);
48:
49: // display the XML document
50: System.out.println(doc.toXML());
51: } catch (ParsingException pe) {
52: System.out.println(“Error parsing document: “ + pe.getMessage());
53: pe.printStackTrace();
54: System.exit(-1);
55: }
56: }
57: }
The DomainEditor application displays the modified XML document to standard output,
so it can be run with the following command to produce a file named feeds2.rss :
java DomainEditor > feed2.rss
Formatting an XML Document
As described earlier, XOM does not retain insignificant whitespace when representing
XML documents. This is in keeping with one of XOM's design goals—to disregard any-
thing that has no syntactic significance in XML. (Another example of this is how text is
treated identically whether created using character entities, CDATA sections, or regular
characters.)
Today's next project is the DomainWriter application, which adds a comment to the
beginning of the XML document feeds2.rss and serializes it with indented lines, pro-
ducing the version shown in Listing 19.5.
19
LISTING 19.5
The Full Text of feeds2.rss
1: <?xml version=”1.0”?>
2: <rss version=”2.0”>
3: <channel>
4: <title>Workbench</title>
5: <link>http://www.cadenhead.org/</link>
6: <item>
7: <title>Fuzzy Zoeller Sues Over Libelous Wikipedia Page</title>
8: </item>
9: </channel>
10: </rss>
 
Search WWH ::




Custom Search