RE: [PHP] Using DOM textContent Property
| From: | Tim Gustafson | Date: | Tue, 02 Sep 2008 22:35:26 +0000 |
| Subject: | RE: [PHP] Using DOM textContent Property | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279357@lists.php.net to get a copy of this message | ||
> if a node has children, then its not a leaf, so i imagine
> you could continue to traverse until you reach the leaf
> that actually has the address needing magical conversion.
I tried that. $Element->hasChildNodes() returns true for just about
everything except tags like <br> and <img> that have no corresponding </br>
or </img> because the content that appears between <p> and </p>, for
example, apparently counts as a child node, even though they're not HTML
tags. So, if you have:
<p>Foo!</p>
when you look at $Element->hasChildNodes() for the <p> tag, you will get
"true", and $Element->childNodes->length is equal to "1", even though
"Foo!"
isn't an HTML tag. Interestingly though, when you iterate through the tree,
you get the <p> tag as one of the elements, but you never get a text-only
element that has that <p> as a parentNode. In fact, get_class($Element)
always returns DOMElement, even on the text-only nodes, which I would have
expected to be DOMText elements...but I guess not. So I'm wondering why
$Element->hasChildNodes() would return true, but iterating through the DOM
tree returns no elements that have that $Element as a parentNode.
What's more, looking at $Element->childNodex->length isn't too helpful,
because, for example:
<h2><a name="bar"></a>Foo</h2>
returns two child nodes, neither of which has "Foo" for its textContent.
Tim Gustafson
SOE Webmaster
UC Santa Cruz
tjg@soe.ucsc.edu
831-459-5354