Home » Core Java » xml » DOM (page 2)

DOM

Add CDATA section to DOM document

In this example we shall show you how to add CDATASection to a DOM Document. We have implemented a method, that is void prettyPrint(Document xml), in order to convert a DOM into a formatted XML String. To add CDATASection to a DOM Document one should perform the following steps: Obtain a new instance of a DocumentBuilderFactory, that is a factory API ...

Read More »

Visit nodes in DOM document recursively

With this example we are going to demonstrate how to visit recursively the nodes in a DOM Document. We have implemented a method void visitRecursively(Node node), in order to visit a node and its children in the DOM Document. In short, to visit recursively the nodes in a DOM Document you should: Obtain a new instance of a DocumentBuilderFactory, that is ...

Read More »

Pretty print XML in Java

This is an example of how to pretty print an xml file in Java. We have implemented a method, that is void prettyPrint(Document xml), in order to transform the DOM Document to a formatted xml String. The steps to get an xml file and pretty print it in a String format using the example’s method is described below: Obtain a new ...

Read More »

Copy nodes subtree from one DOM document to another

In this example we shall show you how to copy the Nodes Subtree from one DOM Document to another. We have implemented a method, that is void prettyPrint(Document xml), in order to convert a DOM into a formatted XML String. To copy the Nodes Subtree from one DOM Document to another one should perform the following steps: Obtain a new ...

Read More »

Create empty DOM document

With this example we are going to demonstrate how to create an empty DOM Document, that represents the entire HTML or XML document. The DOM Document is the root of the document tree, and provides the primary access to the document’s data. In short, to create an empty DOM Document you should: Obtain a new instance of a DocumentBuilderFactory, that ...

Read More »

Parse XML file with DOM

This is an example of how to parse an xml file using a DOM Document. The DOM Document interface represents the entire HTML or XML document and provides the primary access to a document’s data. Parsing an xml file using a DOM Document implies that you should: Obtain a new instance of a DocumentBuilderFactory, that is a factory API that ...

Read More »