Java Reference
In-Depth Information
catch (ParserConfigurationException pce)
{
System.err.println("PCE: "+pce);
}
}
static void dump(Element e)
{
System.out.println("Element:
"+e.getNodeName()+",
"+e.getLocalName()+
",
"+e.getPrefix()+",
"+e.getNamespaceURI());
NodeList nl = e.getChildNodes();
for (int i = 0; i < nl.getLength(); i++)
{
Node node = nl.item(i);
if (node instanceof Element)
dump((Element) node);
else
if (node instanceof Text)
System.out.println("Text:
"+((Text)
node).getWholeText());
}
}
}
ateElement()
method to create the root
movie
element and
movie
's
name
and
language
child elements. It also uses
Document
's
Text createTex-
tNode(String data)
method to create text nodes that are attached to the
name
and
language
nodes. Notice the calls to
Node
's
appendChild()
method, to ap-
pend child nodes (e.g.,
name
) to parent nodes (such as
movie
).
Aftercreatingthistree,
DOMDemo
outputsthetree'selementnodesandotherinform-
ation. This output appears as follows:
Version = 1.0
Encoding = null
Standalone = false