note 107562 added to simplexmlelement.getnamespaces
| From: | harry at nospam dot thestorm dot plus dot com | Date: | Fri, 17 Feb 2012 14:21:39 +0000 |
| Subject: | note 107562 added to simplexmlelement.getnamespaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186192@lists.php.net to get a copy of this message | ||
If the namespace is nested in the xml, then you will have to loop over the nodes.
<?php
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<people xmlns:p="http://example.org/ns"
xmlns:t="http://example.org/test">
<items>
<title>This is a test of namespaces and my patience</title>
<p:person id="1">John Doe</p:person>
<p:person id="2">Susie Q. Public</p:person>
<p:person id="1">Fish Man</p:person>
</items>
</people>
XML;
$sxe = new SimpleXMLElement($xml);
foreach ($sxe as $out_ns)
{
$ns = $out_ns->getNamespaces(true);
$child = $out_ns->children($ns['p']);
}
print_r($child);
foreach ($child as $out)
{
echo $out ."<br />";
}
?>
----
Server IP: 87.124.126.127
Probable Submitter: 94.192.243.26 (proxied: 94.192.243.26)
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.getnamespaces.php
Edit -- https://master.php.net/note/edit/107562
Del: integrated -- https://master.php.net/note/delete/107562/integrated
Del: useless -- https://master.php.net/note/delete/107562/useless
Del: bad code -- https://master.php.net/note/delete/107562/bad+code
Del: spam -- https://master.php.net/note/delete/107562/spam
Del: non-english -- https://master.php.net/note/delete/107562/non-english
Del: in docs -- https://master.php.net/note/delete/107562/in+docs
Del: other reasons-- https://master.php.net/note/delete/107562
Reject -- https://master.php.net/note/reject/107562
Search -- https://master.php.net/manage/user-notes.php