如何解析SOAP响应

时间:2013-04-16 21:59:35

标签: php api soap

我使用SOAP API并且在我的生活中我无法弄清楚如何解析它并将其放入数组中。我得到的回应是:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <get_machinesResponse xmlns="http://127.0.0.1/Integrics/Enswitch/API">
      <s-gensym3>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">1</asterisk_alive>
        <id xsi:type="xsd:string">11</id>
        <server xsi:type="xsd:string">cleveland</server>
        <asterisk xsi:type="xsd:string">1</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.32</ipaddr>
      </s-gensym3>
      <s-gensym5>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">1</asterisk_alive>
        <id xsi:type="xsd:string">13</id>
        <server xsi:type="xsd:string">ernie</server>
        <asterisk xsi:type="xsd:string">1</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.34</ipaddr>
      </s-gensym5>
      <s-gensym7>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">-1</asterisk_alive>
        <id xsi:type="xsd:string">5</id>
        <server xsi:type="xsd:string">lois</server>
        <asterisk xsi:type="xsd:string">0</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.12</ipaddr>
      </s-gensym7>
      <s-gensym9>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">-1</asterisk_alive>
        <id xsi:type="xsd:string">15</id>
        <server xsi:type="xsd:string">mort</server>
        <asterisk xsi:type="xsd:string">0</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.24</ipaddr>
      </s-gensym9>
      <s-gensym11>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">-1</asterisk_alive>
        <id xsi:type="xsd:string">14</id>
        <server xsi:type="xsd:string">muriel</server>
        <asterisk xsi:type="xsd:string">0</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.25</ipaddr>
      </s-gensym11>
      <s-gensym13>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">-1</asterisk_alive>
        <id xsi:type="xsd:string">9</id>
        <server xsi:type="xsd:string">nyc-02</server>
        <asterisk xsi:type="xsd:string">0</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.10</ipaddr>
      </s-gensym13>
      <s-gensym15>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">1</asterisk_alive>
        <id xsi:type="xsd:string">12</id>
        <server xsi:type="xsd:string">ollie</server>
        <asterisk xsi:type="xsd:string">1</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.33</ipaddr>
      </s-gensym15>
      <s-gensym17>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">-1</asterisk_alive>
        <id xsi:type="xsd:string">4</id>
        <server xsi:type="xsd:string">peter</server>
        <asterisk xsi:type="xsd:string">0</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.11</ipaddr>
      </s-gensym17>
      <s-gensym19>
        <quorum_pris xsi:type="xsd:string">1</quorum_pris>
        <description xsi:type="xsd:string" />
        <sip_port xsi:type="xsd:string">5060</sip_port>
        <domain xsi:type="xsd:string">mypbxmanager.net</domain>
        <asterisk_alive xsi:type="xsd:string">-1</asterisk_alive>
        <id xsi:type="xsd:string">8</id>
        <server xsi:type="xsd:string">stewie</server>
        <asterisk xsi:type="xsd:string">0</asterisk>
        <ipaddr xsi:type="xsd:string">10.10.10.13</ipaddr>
      </s-gensym19>
    </get_machinesResponse>
  </soap:Body>
</soap:Envelope>

我通过这样做得到了这个结果:

$foo = new SoapClient("my_3.6.wsdl", array('proxy_host'     => "mydomain.net",
                                            'proxy_port'     => 80,
                                                'trace' => 1));

$result = $foo->get_machines('username', 'password');

$xml = $foo->__getLastResponse();

print_r($xml);

我知道这不是正确的方法,但这是我能够得到回应的唯一方式。我已经做了好几天了。任何建议将不胜感激。

这是我在这里的第一篇文章,如果我没有正确发布,请耐心等待。

1 个答案:

答案 0 :(得分:0)

当我前一段时间遇到类似的问题时,我找到了this post帮助。