note 109078 deleted from simplexmlelement.getnamespaces by danbrown
| From: | danbrown@php.net | Date: | Tue, 19 Jun 2012 13:43:52 +0000 |
| Subject: | note 109078 deleted from simplexmlelement.getnamespaces by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188690@lists.php.net to get a copy of this message | ||
Note Submitter: harry at nospam dot thestorm dot plus do
----
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 />";
}
}
?>