Skip navigation links

Package diva.util.xml

A package of utilities for the XML parsing and printing.

See: Description

Package diva.util.xml Description

A package of utilities for the XML parsing and printing. The central class in this package is the XmlDocument class. Each XmlDocument contains a tree of XML elements, represented by XmlElement objects. The XmlDocument knows how to print itself and perform other useful operations. However, it does not know how to parse itself into existence. For that, an XmlReader object must be used to populate the XmlDocument.

The XmlReader class will parse any legal XML file (containing a reference to its DTD) and produce a parsed tree of XmlElements which it inserts into the document. The application can then traverse the tree to extract data or to build its own internal data structure. Here is an example illustrating a typical use of the XmlReader to process an XML file:

XmlDocument document = new XmlDocument(new URL("file:/..."));
XmlReader reader = new XmlReader();
if (reader.errorCount > 0) { something...
XmlElement root = document.getRoot();
for (Iterator i = root.elements(); i.hasNext();) {
    ... process each child element... 

To create an XML file, the application creates a tree of XmlElements and inserts it into an XmlDocument. It then calls the write() method with a Writer object. Here is an example illustrating a typical use:

XmlElement root = new XmlElement();
... Add child elements to the root ...

XmlDocument document = new XmlDocument("file:/...");
XmlWriter writer = new XmlWriter();
Skip navigation links