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 ...
Get Java™ Phrasebook 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.