Package diva.util.xml

A package of utilities for the XML parsing and printing.

See:
          Description

Interface Summary
XmlBuilder An XmlBuilder is an interface that can be implemented by classes that convert between XmlElements and some internal data representation.
 

Class Summary
AbstractXmlBuilder An abstract implementation of the XmlBuilder interface that gets and sets a delegate, leaves the build method abstract, and doesn't support the generate method.
CompositeBuilder CompositeBuilder is a non-validating parser that uses other builders to parse and generate XML files from arbitrary collections of objects.
XmlDemo A simple program that you can run to illustrate the operation of the files in this package.
XmlDocument An XMLDocument is an in-memory representation of an XML document.
XmlElement An XmlElement is a node of a tree representing an XML file.
XmlReader An XmlReader reads a character stream and constructs the internal data of an XmlDocument.
XmlUtilities A collection of utility methods for XML-related operations.
XmlWriter Given a tree of XmlElements, an object of this class generates the equivalent XML into an output stream.
 

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();
reader.setVerbose(true);
reader.parse(document);
if (reader.errorCount > 0) {
    ...do something...
    return;
}
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:/...");
document.setRoot(root);
XmlWriter writer = new XmlWriter();
writer.setVerbose(true);
writer.write(document);