Re: Help with XML processing using DOM
- From: "Jeff Higgins" <oohiggins@xxxxxxxxx>
- Date: Thu, 28 Jun 2007 06:50:28 -0400
"kernco" <razael1@xxxxxxxxx> wrote in message
news:1183021310.434884.270330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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
try Element.getTagName()
.
- Follow-Ups:
- Re: Help with XML processing using DOM
- From: kernco
- Re: Help with XML processing using DOM
- References:
- Help with XML processing using DOM
- From: kernco
- Help with XML processing using DOM
- Prev by Date: Help with XML processing using DOM
- Next by Date: Re: Sort Method Conversion
- Previous by thread: Help with XML processing using DOM
- Next by thread: Re: Help with XML processing using DOM
- Index(es):
Relevant Pages
|