xml - xpath php slect text and child node in order -
i have xml this:
<p>tex text</p> <p><a2>subchild text</a2> text text text</p>
i extract text (from p , kid nodes) in written order , set result in string. utilize next query
$text = $currentnode->xpath("p[not(@class='notes')]/text()) foreach($text $tex) { $finaltext .= $tex." "; }
the problem cannot child-nodes text, illustration text of node 'a2' in example. help? thanks
/text () looks immediate text nodes, //text () looks immediate or lower nodes. it's short descendent-or-self::text ().
so query needs slash:
$text = $currentnode->xpath("p[not(@class='notes')]//text());
(assuming want text , not copies of kid elements).
xml xpath
No comments:
Post a Comment