note 109078 added to simplexmlelement.getnamespaces
| From: | harryatnospamdotthestormdotplusdo | Date: | Tue, 19 Jun 2012 11:53:10 +0000 |
| Subject: | note 109078 added to simplexmlelement.getnamespaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188687@lists.php.net to get a copy of this message | ||
This a correction to the previous post. The previous post will work, but will not take account of
multiple entries in the xml. I have just moved the second foreach loop inside the first.
<?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']);
foreach ($child as $out)
{
echo $out . "<br />";
}
}
?>
----
Server IP: 87.124.126.48
Probable Submitter: 94.192.243.26
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.getnamespaces.php
Edit -- https://master.php.net/note/edit/109078
Del: integrated -- https://master.php.net/note/delete/109078/integrated
Del: useless -- https://master.php.net/note/delete/109078/useless
Del: bad code -- https://master.php.net/note/delete/109078/bad+code
Del: spam -- https://master.php.net/note/delete/109078/spam
Del: non-english -- https://master.php.net/note/delete/109078/non-english
Del: in docs -- https://master.php.net/note/delete/109078/in+docs
Del: other reasons-- https://master.php.net/note/delete/109078
Reject -- https://master.php.net/note/reject/109078
Search -- https://master.php.net/manage/user-notes.php