ID:               44108
 Comment by:       hubert dot roksor at gmail dot com
 Reported By:      php dot net at trueprices dot net
 Status:           Open
 Bug Type:         SimpleXML related
 Operating System: Debian
 PHP Version:      5.2.5
 New Comment:

If $child2 is <wsdl:operation/> then $child3 will be <wsdl:input/> or
<wsdl:output/> and there will be no $child4.

Unless this behaviour is considered as a bug by the developer and until
it is fixed, you'll have to specify the children's namespace when
calling children():
- $child2->children('http://schemas.xmlsoap.org/wsdl/') on PHP 5.1 and
later or
- $child2->children('wsdl', true) on PHP 5.2 and later


Previous Comments:
------------------------------------------------------------------------

[2008-02-13 12:47:53] php dot net at trueprices dot net

Description:
------------
SimpleXMLelement has no children() on element with only attributes?

I try to retreive an element by xpath which goes without problems, The
child elements it contains (same namespace) are all empty element with
only attributes. However the returned SimpleXML element does not contain
any children? so i'm unable to retreive there attributes.




Reproduce code:
---------------
<?php
$data = '<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions 
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
  targetNamespace="http://www.w3.org/2001/XMLSchema";
>
<wsdl:portType name="qxqPortType">
        <wsdl:operation name="SOAP_set">
            <wsdl:input message="SetRequest"/>
            <wsdl:output message="SetResponse"/>
        </wsdl:operation>
    <wsdl:operation name="SOAP_get">
            <wsdl:input message="GetRequest"/>
            <wsdl:output message="GetResponse"/>
        </wsdl:operation>        
</wsdl:portType>
</wsdl:definitions>';

echo '<pre>';
$xml = simplexml_load_string($data);
if ($xml)
{

  $res2 = $xml->xpath('//wsdl:portType/wsdl:operation');
  //print_r($res);
  foreach ($res2 as $child2)
  {
    //print_r($child2->children());
    echo 'child2'.PHP_EOL;
    print_r($child2->getName().PHP_EOL);
    print_r(count($child2->children()).PHP_EOL);
    print_r($child2);
    
    foreach ($child2->children() as $child3)
    {
      echo 'child3'.PHP_EOL;
      print_r($child3->getName().PHP_EOL);
      print_r(count($child3->children()).PHP_EOL);
      print_r($child3);
      foreach ($child3->children() as $child4)
      {
        echo 'child4'.PHP_EOL;
        print_r($child4->getName().PHP_EOL);
        print_r(count($child4->children()).PHP_EOL);
        print_r($child4);
      }
    }

  }
}
echo '</pre>';
?>

Expected result:
----------------
child2 & child3 & child4 should be printed..
 

child2
operation
2
SimpleXMLElement Object
(
    [EMAIL PROTECTED] => Array
        (
            [name] => SOAP_set
        )

)
child2
operation
2
SimpleXMLElement Object
(
    [EMAIL PROTECTED] => Array
        (
            [name] => SOAP_set
        )
   /* 2 another simplexml element input & output with children &
attributes*/
)

Actual result:
--------------
Only child2 prints with 0 children

child2
operation
0
SimpleXMLElement Object
(
    [EMAIL PROTECTED] => Array
        (
            [name] => SOAP_set
        )

)
child2
operation
0
SimpleXMLElement Object
(
    [EMAIL PROTECTED] => Array
        (
            [name] => SOAP_get
        )

)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44108&edit=1

Reply via email to