|
|
Child nodes contain the data in which we are interested.
-
When we get a child Node, we can recursively get more children
Nodes
with the getChildNodes method, or get the attributes of that
Node. This is how we can iterate through the tags and nested
tags of our XML doucment.
-
Be warned, even if your node only contains other elements, the parser counts
white space between tags as other nodes. However, you can write a
DTD to tell it to ignore these.
-
Elements are represented by objects that implement interface Element,
which extends interface Node.
On the other hand, text are represented by objects that implement Text,
which also extends Node, but does not extend Element.
So you can use the instanceof Element test to ignore whitespace.
-
Once we've found the node in which we are interested, we can use the getData
method of Text to get the String.
-
More handy methods to traverse:
-
getLastChild to get the last child node.
-
getNextSibling to get the next node on the same level.
Getting Attributes
|