Help with XML processing using DOM



I'm trying to use XML files as input to my program. I decided to use
the DOM (DocumentBuilder, Node, etc.) instead of SAX. I have loaded
the file into an instance of Document, call it 'doc', and now I want
to go through and extract the data.

XML file:
<?xml version="1.0"?>

<a>
<b>
<c>foo</c>
<d>foo</d>
<d>foo</d>
</b>
<e>
</e>
</a>

Relevant code:
Node domNode = doc.getDocumentElement();
System.out.println(domNode.getNodeName());
domNode = domNode.getFirstChild();
System.out.println(domNode.getNodeName());

do {
if (domNode.getNodeName().equals("b")) {
...
} else if ...
...
} while ((domNode = domNode.getNextSibling()) != null);


You will notice my println statements there to help figure out the
problem. The first one prints "a" as expected, I'd then expect the
first child to be "b", but instead it prints "#text". I changed the
second println to print the node value instead of name, and it prints
a single whitespace character. Why isn't this getting the Node at
"b"?

Thanks,
Colin

.