Matt
Matt

Reputation: 5511

DOM - Parsing text from a node

According to this page, I think I have done this right... or at least so I think.

I want to parse this:

<Title>Bananas</Title>

Here is some code.

node1.getNodeName();                  // returns "Title"   *correct*
node2 = node1.getNextSibling();
node2.getNodeName();                  // returns "#text"   *correct*
node2.getNodeType() == Node.TEXT_NODE // returns true      *correct*
node2.getNodeValue();                 // returns ""        *should return "Bananas"*

According to the documentation, shouldn't the call to getNodeValue() on a Text Node return its text value?

Upvotes: 1

Views: 675

Answers (1)

Kurru
Kurru

Reputation: 14331

You're accessing the text after the </title> You probably want something like node1.getFirstChild()

Use this line instead

node2 = node1.getFirstChild();

Upvotes: 1

Related Questions