I got an XML response as
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.*********.in">
<SOAP-ENV:Body>
<ns1:LoginResponse>
<return>
<SessionID>3AC46E3F62</SessionID>
<ResponseCode>0</ResponseCode>
<ResponseMessage>Successful</ResponseMessage>
</return>
</ns1:LoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I parse the SessionID and ResponseCode from this xml using PHP.Im unable to do this.Please suggest some methods to do this.
Check this : How can I get and process a response from a PHP API and apply print_r(htmlentities($xmldata->asXML())); to your XML response
and this too : soap:Envelope SOAP-ENV:Envelope PHP
the responses from there maybe will help you , of course you may code yourself cause is very easy
Check this code too is already working example (very close to your problem):
<?php
$a ='<soap-env:envelope xmlns:ns1="http://v3.core.com.productserve.com/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<ns1:getproductlistresponse>
<oproduct>
<iid>113133802</iid>
<icategoryid>270</icategoryid>
<imerchantid>1547</imerchantid>
<iadult>0</iadult>
<sname>The Ashes / 5th Test - England v Australia - Day 1</sname>
<sawdeeplink>http://www.awin1.com/pclick.php?p=113133802&a=111402&m=1547&platform=cs</sawdeeplink>
<sawthumburl>http://images.productserve.com/thumb/1547/113133802.jpg</sawthumburl>
<fprice>119.99</fprice>
</oproduct>
</ns1:getproductlistresponse>
</soap-env:body>
</soap-env:envelope>';
$xml = simplexml_load_string($a);
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['soap-env']);
$getproductlistresponse = $soap->body->children($ns['ns1']);
foreach ($getproductlistresponse->children() as $item)
{
//This example just accesses the iid node but the others are all available.
echo (string) $item->iid . '<br />';
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.