23.2. DOM Example: Representing an XML Document as a JTree

Listing 23.1 shows a class that represents the basic structure of an XML document as a JTree. Each element is represented as a node in the tree, with tree node being either the element name or the element name followed by a list of the attributes in parentheses. This class performs the following steps:

1.
Parses and normalizes an XML document, then obtains the root element. These steps are performed exactly as described in steps one through five of the previous section.
2.
Makes the root element into a JTree node. If the XML element has attributes (as given by node.getAttributes), the tree node is represented by a string composed of the element name (getNodeName) followed by the attributes ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.