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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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: Sun Dec 22 05:01:30 2024 UTC