17.3. “Hello Apache”

In this section, you gain a little momentum, and a success or two, before digging into the nittygritty of Xerces. You use basic DOM methods to create a simple XML document, and then you reverse the process and parse an existing XML document.

17.3.1. Your First Parser

Listing 17.1 is a complete program that creates a few XML elements and then displays the serialized XML. The name of the file is HelloApache.java.

Listing 17.1. HelloApache Example
 import java.io.StringWriter; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.apache.xerces.dom.DocumentImpl; import org.apache.xerces.dom.DOMImplementationImpl; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.Serializer; import org.apache.xml.serialize.XMLSerializer; ...

Get XML Schema Complete Reference, The 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.