
April 1st, 2008, 10:18 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Time spent in forums: 2 h 25 m 46 sec
Reputation Power: 0
|
|
|
Using DOM to grab text in mixed content
How do you grab the text value of a node but exclude the text content of some of the child nodes. For example, if I had XML that contains mixed content like this:
Code:
<titles>
<title>The Story of <em>ABC</em></title>
<title>The End of XYZ</title>
<title>50 Ways to <em>ABC</em> with XYZ<footnote num="1">This book is banned in Chicago</footnote></title>
</titles>
I want to put the titles into an array, but I do not want to any of the content from the footnote tag. If I use "->textContent" I get the content of all decendants. Same with "->NodeValue".
PHP Code:
public function GetTitles(){
$xp = new domxpath($this->dom);
$node = $xp->query("//title");
$titles = array();
foreach($node as $contents) {
$titles[] = $contents->nodeValue;
}
return $titles;
}
Is there a way to exclude the content of the "footnote" child nodes from the array without excluding the content of other nodes, such as the "em" tags?
Any ideas?
|