2

Here's the response from a WSDL

<return code='6000'></return>

I would like to return the code value. Can i use simplexml_load_string() ?

alex
  • 479,566
  • 201
  • 878
  • 984
user1189060
  • 73
  • 1
  • 5

2 Answers2

0

Yes, you can.

$xml = simplexml_load_string($str);

$code = (int) $xml->attributes()->code;

CodePad.

alex
  • 479,566
  • 201
  • 878
  • 984
0

You can use DOMDocument() to get node values as well as attribute values.

$dom_boj=new DOMDocument(); //Creating object to the class DOMDocument()
$dom_boj->loadXML($XMLResponse); // loading your response using loadXML

//Traversing all return tags. 

foreach($dom_boj->getElementByTagName('return') as $tagName)  
{            
                 echo $tagName->getAttribute('code');   
}
alex
  • 479,566
  • 201
  • 878
  • 984
Hearaman
  • 8,466
  • 13
  • 41
  • 58