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:
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.
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 ...