Page 1 of 1

simplexml doesn't return all namespaces

Posted: Thu Feb 05, 2009 2:56 pm
by crazycoders
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:

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>
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/
)

Re: simplexml doesn't return all namespaces

Posted: Fri Feb 06, 2009 7:48 am
by crazycoders
No one? Is there a different technology i could use to read all the nodes of an XML file. I don't care if its another library, as long as it's fast and efficient, so nothing coded in PHP, i want compiled PHP extensions...