php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66044 SimpleXMLElement::children
Submitted: 2013-11-07 09:49 UTC Modified: 2013-11-07 18:19 UTC
From: contact at cosminsandu dot ro Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: contact at cosminsandu dot ro
New email:
PHP Version: OS:

 

 [2013-11-07 09:49 UTC] contact at cosminsandu dot ro
Description:
------------
the SimpleXMLElement::children does not return correct children(s) if the namespace is defined in child element


Test script:
---------------
http://stackoverflow.com/questions/19832026/php-simplexmlelement-get-children-with-another-xml-namespace


Expected result:
----------------
the q1 element:

    <q1:login xmlns:q1="THE NAMESPACE I NEED">
        <user xsi:type="xsd:string">user</user>
        <password xsi:type="xsd:string">pass</password>
    </q1:login>

Actual result:
--------------
the $body_node->count() return 0; 
and $body_node->children()->asXML() returns false.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-07 18:19 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2013-11-07 18:19 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

children() and attributes(), as well as ->, will only return children/attributes of the "current namespace", which uses the default of xmlns="". To switch namespaces pass arguments.

$xml = new SimpleXMLElement("your XML", 0, false);
$body_node = $xml->children("soap", true)->Body;
$login_node = $body_node->children("q1", true)->login;
$user_node = $login_node->children("")->user;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 00:01:28 2024 UTC