[PHP] SimpleXML & namespaces, empty elements probleem?

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Helza
  • Registratie: Maart 2003
  • Laatst online: 11-09 16:01
Hallo,

Ik krijg het maar niet voor elkaar om met SimpleXML de kinderen van een XML element terug te krijgen die binnen een namespace zitten en alleen maar attributen hebben.

Ik kan ze via xpath() wel direct terug krijgen, maar ik kom er niet bij via de parent met (children())

Ik will alle "message" attributen van elk operation command krijgen.. maar telkens als ik de operation opvraag via xpath krijg ik simplexml element zonder kinderen..

Ziet iemand wat ik verkeerd doe?

mijn code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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>';
?>

Acties:
  • 0 Henk 'm!

  • steffex
  • Registratie: Augustus 2003
  • Laatst online: 12-08 00:24
Atributes worden als array keys gezien... Bekijk ook nog ff example #5 in de manual: http://www.php.net/simplexml
PHP:
1
print_r($child4['message']);

Acties:
  • 0 Henk 'm!

  • Helza
  • Registratie: Maart 2003
  • Laatst online: 11-09 16:01
Ik weet dat message een attribuut is, maar er zijn geen chilrden volgens count($child2->children())
Dus hij komt niet eens bij 3, laat staan child 4 :(

Acties:
  • 0 Henk 'm!

  • FragFrog
  • Registratie: September 2001
  • Laatst online: 09:34
http://nl2.php.net/manual...exml-element-children.php
Note: SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.
:?

Wat geeft een var_dump van $child2 eigenlijk?

Mmm, even getest, blijft zo te zien leeg. Vreemd :+

[ Voor 17% gewijzigd door FragFrog op 11-02-2008 21:07 ]

[ Site ] [ twitch ] [ jijbuis ]


Acties:
  • 0 Henk 'm!

  • Helza
  • Registratie: Maart 2003
  • Laatst online: 11-09 16:01
iedereen bedankt voor de hulp, de oplossing is gevonden :)

Het is niet
$child2->children()
Maar
$child2->children('wsdl',true)
of
$child2->children('http://schemas.xmlsoap.org/wsdl/',true)
(afhankelijk of de namespace al geregistreerd is)