Download The Java™ Web Services Tutorial
Transcript
254
DOCUMENT OBJECT MODEL
title elements, you set up the contents of this arrays so it would work with
either data file.
Note: The mechanism you are creating here depends on the fact that structure nodes
like slideshow and slide never contain text, while text usually does appear in content nodes like item. Although those “content” nodes may contain subelements in
slideShow10.xml, the DTD constrains those subelements to be XHTML nodes.
Because they are XHTML nodes (an XML version of HTML that is constrained to
be well-formed), the entire substructure under an item node can be combined into
a single string and displayed in the htmlPane that makes up the other half of the
application window. In the second part of this section, you’ll do that concatenation,
displaying the text and XHTML as content in the htmlPane.
Although you could simply reference the node types defined in the class,
org.w3c.dom.Node, defining the ELEMENT_TYPE constant keeps the code a little
more readable. Each node in the DOM has a name, a type, and (potentially) a list
of subnodes. The functions that return these values are getNodeName(), getNodeType, and getChildNodes(). Defining our own constants will let us write
code like this:
Node node = nodeList.item(i);
int type = node.getNodeType();
if (type == ELEMENT_TYPE) {
....
As a stylistic choice, the extra constants help us keep the reader (and ourselves!)
clear about what we’re doing. Here, it is fairly clear when we are dealing with a
node object, and when we are dealing with a type constant. Otherwise, it would
be fairly tempting to code something like, if (node == ELEMENT_NODE), which
of course would not work at all.
Control Node Visibility
The next step is to modify the AdapterNode’s childCount function so that it
only counts “tree element” nodes—nodes which are designated as displayable in
the JTree. Make the modifications highlighted below to do that:
public class DomEcho extends JPanel
{
...
public class AdapterNode
{
Related documents
The J2EE™ 1.4 Tutorial
View - ITtestpapers.com
The Java™ Web Services Tutorial
THE J2EE™ 1.4 Tutorial in NetBeans
GridForce - University at Buffalo, Computer Science and
WebLogic Web Service
Guide for protecting boreholes
MIS User Manual (MoW, 2013)
Global - US English
Groundwater Monitoring for Pump Operators
HAZUS MR2 Hurricane User Manual Volume I
[1 ] Oracle® Enterprise Manager
MANUEL D`UTILISATION SOUS WINDOWS
Sun GlassFish Enterprise Server 21 Quick Start Guide
Wiley Java 2 Enterprise Edition 1.4 (J2EE 1.4) Bible