Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi2 all


if the xml tag has more than one namespace value i can only get first value

here is what i mean


XML
<?php

$xml = <<<XML
<?xml version="1.0" standalone="yes"?>
<people xmlns:p="http://example.org/ns" xmlns:t="http://example.org/test">
    <p:person id="1">John Doe</p:person>
    <p:person id="2">Susie Q. Public</p:person>
</people>
XML;

$sxe = new SimpleXMLElement($xml);

$namespaces = $sxe->getNamespaces(true);
var_dump($namespaces);

?>



returns
C#
array(1) {
  ["p"]=>
  string(21) "http://example.org/ns"
}


i need also
PHP
http://example.org/test 

how to get that
Posted

1 solution

Use getDocNamespaces(true), as documented here: http://www.php.net/manual/en/simplexmlelement.getdocnamespaces.php[^].

Making that switch returns
array (size=2)
  'p' => string 'http://example.org/ns' (length=21)
  't' => string 'http://example.org/test' (length=23)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900