simplexml doesn't return all namespaces
Posted: Thu Feb 05, 2009 2:56 pm
It's strange, i'm using simplexml to load a document that contains several namespaces but only one seems to be detected. Can anyone point out what i'm doing wrong:
Starting PHP Processor
Loading /var/www/vhosts/allianceunisport.com/httpdocs/tests/mypage.phpx
Reading XML content
Inspected element: page
Inspected element: body
Inspected element: br
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Inspected element: label
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Inspected element: button
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Code: Select all
$xmlcontent = simplexml_load_file($_SERVER['PATH_TRANSLATED']);
header('content-type: text/plain');
readnodes($xmlcontent, $xmlcontent->getNamespaces());
function readnodes(simplexmlelement $item, array $namespaces){
//Output the simplexmlelement's name
echo 'Inspected element: '.$item->getName().CRLF;
//Output the items without a namespace
foreach($item->children() as $children){
readnodes($children, $namespaces);
}
//Output the items per namespace
print_r($namespaces);
foreach($namespaces as $namespace){
foreach($item->children($namespace) as $children){
readnodes($children, $namespaces);
}
}
}Code: Select all
<phpx:page codebehind="mypage.php" xmlns:phpx="http://www.allianceunisport.com/phpx/1.0/syntax/" xmlns:phpxgrids="http://www.allianceunisport.com/phpxgrids/1.0/syntax/">
<body>
<phpx:label id="startapplabel" text="Click this button to start the application: " />
<phpx:button id="startapp" text="Start Application" />
<br />
<phpxgrids:grid id="datagrid">
<phpxgrids:row>
<phpxgrids:column>
32
</phpxgrids:column>
<phpxgrids:column>
apples
</phpxgrids:column>
</phpxgrids:row>
<phpxgrids:row>
<phpxgrids:column>
17
</phpxgrids:column>
<phpxgrids:column>
banana
</phpxgrids:column>
</phpxgrids:row>
</phpxgrids:grid>
</body>
</phpx:page>Loading /var/www/vhosts/allianceunisport.com/httpdocs/tests/mypage.phpx
Reading XML content
Inspected element: page
Inspected element: body
Inspected element: br
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Inspected element: label
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Inspected element: button
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)
Array
(
[phpx] => http://www.allianceunisport.com/phpx/1.0/syntax/
)