W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2005

Re: getTextContent, JDK1.4

From: <wdowiak@poczta.onet.pl>
Date: Fri, 25 Nov 2005 15:25:09 +0100
To: www-dom@w3.org
Message-Id: <20051125142540Z693063-21682+910@kps2.test.onet.pl>
('binary' encoding is not supported, stored as-is)
You are dealing with an Element Node that has a text value.


The getNodeValue() method on this element returns null, as per
specification. However, the child Node of Element in question -- if there is
indeed text content -- is going to be a Text Node. The value of this Text
Node is what you are after.


To replicate getTextContent(), you need something like:


NodeList matchingNodes = document.getElementsByTagName(nodeName);
Node matchingNode = matchingNodes.item(whichOne); 

// The node we've found is an Element - get its child with text value
return matchingNode.getChildNodes().item(0).getNodeValue(); // of course,
you'd check if the child node is there indeed, and if it is text ...


hope this helps,


GW / http://eaiblueprint.com



Received on Sunday, 27 November 2005 01:41:41 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:12 UTC