-3

This is how i send the request

$header = "POST 213.207.000.000/services/AmountCharging/v3 HTTP/1.1 \r\n"; $header .= "Content-type: text/xml;charset=UTF-8 \r\n"; 
$header .= "Content-length: ".strlen($request_xml)." \r\n"; 
$header .= "Content-transfer-encoding: text \r\n"; 
$header .= "Connection: Keep-Alive \r\n\r\n"; 
$header .= $request_xml; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$strxml = curl_exec($ch);  

Below is my XML response, and using php I want to grab just the contents of <soapenv:Body></soapenv:Body>

<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:chargeAmountResponse xmlns:ns1="http://www.csapi.org/schema/parlayx/payment/amount_charging/v3_1/local"></ns1:chargeAmountResponse>
</soapenv:Body>
</soapenv:Envelope>

Any ideas? Thank you..

andreas777
  • 349
  • 1
  • 6
  • 23

1 Answers1

0

Given that there really is nothing worth seeing within the soapenv:Body the following doesn't really show anything interesting but should help.

$strxml='<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <ns1:chargeAmountResponse xmlns:ns1="http://www.csapi.org/schema/parlayx/payment/amount_charging/v3_1/local"></ns1:chargeAmountResponse>
    </soapenv:Body>
</soapenv:Envelope>';

$dom=new DOMDocument;
$dom->loadXML( $strxml );
$body=$dom->getElementsByTagNameNS('http://schemas.xmlsoap.org/soap/envelope/','Body')->item(0);
echo 'Body: '.$body->tagName.', Child: '.$body->childNodes->item(1)->tagName.', Attribute: '.$body->childNodes->item(1)->getAttribute('xmlns:ns1');


Output
------
Body: soapenv:Body, Child: ns1:chargeAmountResponse, Attribute: http://www.csapi.org/schema/parlayx/payment/amount_charging/v3_1/local


update:
-------

Given that it does appear supplying a single line string causes errors
you could aproach it slightly differently.

$col=$dom->getElementsByTagName('*');
foreach( $col as $node ) {
    echo 'tag:'.$node->tagName.' value:'.$node->nodeValue.BR;   
}
Professor Abronsius
  • 30,177
  • 5
  • 29
  • 43
  • For the line of echo i get the following error message: -> Notice: Trying to get property of non-object Fatal error: Call to a member function getAttribute() – andreas777 Jan 28 '16 at 14:11
  • RamRaider, when i put $strxml as above example you stated it works, but when i incorporate it in my code as from $strxml= curl_exec($ch); it doesnt, whys that? – andreas777 Jan 28 '16 at 15:13
  • that depends upon your code - having not seen the code it is hard to tell. – Professor Abronsius Jan 28 '16 at 15:57
  • Please check above i have added my curl request and process code. thank you – andreas777 Jan 29 '16 at 08:55
  • I have noticed that the $strxml = curl_exec($ch); is a single line, which doesnt work with the code you provided. How i can convert this to XML standard format with the break lines? – andreas777 Jan 29 '16 at 12:28
  • it should not matter that the response ( `$strxml` ) is a single line or not. If you echo $strxml rather than try to process it is it valid xml? – Professor Abronsius Jan 29 '16 at 12:47
  • when i run your code as multilined it works. when i remove the line breaks and $strxml becomes single line i get the following error: (Line 122: the echo line) Notice: Trying to get property of non-object in xml.php on line 122 Fatal error: Call to a member function getAttribute() on null in xml.php on line 122 – andreas777 Jan 29 '16 at 13:24