O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an XML Document with DOM

DocumentBuilderFactory fact =
											DocumentBuilderFactory.newInstance( );
											DocumentBuilder builder =
											fact.newDocumentBuilder( );
											Document doc = builder.newDocument( );
											Element location = doc.createElement("Location");
											doc.appendChild(location);
											Element address = doc.createElement("Address");
											location.appendChild(address);
											Element city = doc.createElement("City");
											address.appendChild(city);
											line.appendChild(doc.createTextNode("Flat Rock"));
											Element state = doc.createElement("State");
											address.appendChild(state);
											state.appendChild(doc.createTextNode("Michigan"));
											((org.apache.crimson.tree.XmlDocument)doc).
											write(System.out);

In this phrase, we use the DOM API and JAXP to create an XML document. The XML segment created ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required