note 94917 added to simplexmlelement.xpath
| From: | DrupalFocus at earthlink dot net | Date: | Wed, 02 Dec 2009 20:27:55 +0000 |
| Subject: | note 94917 added to simplexmlelement.xpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163502@lists.php.net to get a copy of this message | ||
Looks like the relative path is relative to the SimpleXMLElement object that you call the Xpath()
method on. Basically chopping off the root element.
$string = <<<XML
<foo>
<bar>
<a>
<b>
<c>text</c>
<c>stuff</c>
</b>
<d>
<c>code</c>
</d>
</a>
</bar>
</foo>
XML;
$xml = new SimpleXMLElement($string);
/* Search for children using 2nds level relative <bar><a><b><c> */
$result = $xml->xpath('a/b/c');
if ($result)
foreach($result as $node) {
drupal_set_message(t('a/b/c: @node.', array('@node' => $node)));
}
else
drupal_set_message(t('a/b/c: failed.'));
/* it relative to the SimpleXMLElement Search for 2nds level relative
<bar><a><b><c> but where is foo */
$bar = $xml->bar;
$result = $bar->xpath('a/b/c');
foreach($result as $node) {
drupal_set_message(t('bar->a/b/c: @node.', array('@node' => $node)));
}
results in :
#
# a/b/c: failed.
# bar->a/b/c: text.
# bar->a/b/c: stuff.
----
Server IP: 69.147.83.197
Probable Submitter: 65.88.88.75
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.xpath.php
Edit -- https://master.php.net/note/edit/94917
Del: integrated -- https://master.php.net/note/delete/94917/integrated
Del: useless -- https://master.php.net/note/delete/94917/useless
Del: bad code -- https://master.php.net/note/delete/94917/bad+code
Del: spam -- https://master.php.net/note/delete/94917/spam
Del: non-english -- https://master.php.net/note/delete/94917/non-english
Del: in docs -- https://master.php.net/note/delete/94917/in+docs
Del: other reasons-- https://master.php.net/note/delete/94917
Reject -- https://master.php.net/note/reject/94917
Search -- https://master.php.net/manage/user-notes.php