...As Jeff pointed out, your code probably has an error: you expect that the first child of the element is element but in fact it is a Text node, hence you get a CastException.
Instead, to traverse the DOM Tree you need to write some kind of a switch statement, switching on a nodeType and casting to appropriate node, see samples/dom/Counter.java.
The question probably was, is there some magic switch that will make "insignificant" whitespace go away? Nope. You also have to deal with insignificant comments and processing instructions.
This is such a common use case, you (Tim) might find it useful to implement two helper functions:
public Element getFirstElementChild(Element parent) {
return findElement(parent.getFirstChild());
}public Element getNextElementSibling(Node node) {
return findElement(node.getNextSibling());
}private Element findElement(Node node) {
while (node != null && node.getNodeType() != Node.ELEMENT_NODE)
node = node.getNextSibling();
return node;
}// typed from memory - if they don't compile/run, fix 'em
You could add error checking for non-whitespace text if desired.
Bob Foster http://xmlbuddy.com/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
