PHP 8.5.0 Beta 1 available for testing

Voting

: six minus six?
(Example: nine)

The Note You're Voting On

harry at nospam dot thestorm dot plus dot com
13 years ago
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']);




    foreach ($child as $out)
    {
        echo $out . "<br />";
    }
}
?>

<< Back to user notes page

To Top