Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting text value: nodeValue -vs- childNodes

Status
Not open for further replies.

fuzzydonut

Programmer
Nov 21, 2002
1
US
Hi, everyone.

I'll probably get kicked for this question but I've got to understand something...

My question has to do with extracting the contents of a tag into a variable. I.e. <mytag>desired value</mytag>

I've seen this done two ways.

Way #1
slideText = newSlideNode.firstChild.nodeValue;

Way #2
foovar = rootNode.childNodes[idx].childNodes[2].childNodes;

The nodeValue seems to make sense. I want a value, it's in a node. Cool! But it doesn't alway work.

And, isn't childNodes[] just a collection, and with that you still have to fish through the collection to get the property you want (like the tag's value)?

Way #3 - They way it should be ;-)
myvalue = rootNode.childNode[idx].nodeValue;

I've got my program working but this &quot;inconsistency&quot; has me reaching for another beer.

Thanks in advance for any answer or insult.

 
nodeValue: will only return a value if the node is a &quot;text node&quot; otherwise return 'null' Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top