As usual, I am skipping the Swing details. You can see that once the
document is loaded using SAXBuilder, though, the
root element of that document is obtained (in the
initialize( ) method). This element is used to
create an instance of JDOMNode through the
createNode( ) utility function. The function
simply converts between JDOM types and JDOMNode
implementations, and took about 15 seconds to code up. Use a similar
method in your own programs that use decorators and wrappers.
Once I've got JDOMNode implementations,
it's simple to walk the tree, creating visual objects for each
node encountered. Additionally, for each node, I've set the
status text of the window to the XPath expression for that node. You
can compile all of these examples, and run them using this command:
C:\javaxml2\build>java javaxml2.SimpleXPathViewer
c:\javaxml2\ch08\xml\contents.xml
Finally, I'd like to thank Philip Nelson, who did the
lion's share of the work on the decorator code shown here.
Philip has really explored using decorators with JDOM, and was a
great help in this section.