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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.