Breaking News
Home / Java / Java Tutorials / How to construct DOM and convert to XML?

How to construct DOM and convert to XML?

DOM to XML  Constructing DOM (Document Object Model) to generate or represent XML is easy. The basic steps are as follows

> Create the XML Document  object using the Document Builder Factory.

>Build your model by adding nodes and attributes etc. in the hierarchical order

> Once done, transform your XML Document to XML String representation by using an Transformer .

The following code snippet shows how to create DOM and then transform it into an XML String representation using the transformer. At run time the JVM would pick up the configured DocumentBuilder and as well as the Transformer.

If any one of these implementation is not found, it would throw a RuntimeException like NoClassDefFoundException and abort.


The following is the output xml of the above snippet.
<!–This is root node–>
<child name=”value”>This is child node value</child>


Check Also

Have a Question

How to select a JVM Analyzing Tool?

A JVM monitoring tool also know as a Diagnostic might be needed to fine tune …

Advertisment ad adsense adlogger