Designing and Development > Programming

How to parse XML-Rpc Ping request in PHP

(1/1)

girish baghel:
I have problem in parsing xml-RPC response,
(say we have following string) 
--- Code: ---$responseXML = '<?xml version="1.0"?>
<methodResponse>
   <fault>
      <value>
         <struct>
            <member>
               <name>faultCode</name>
               <value><int>4</int></value>
               </member>
            <member>
               <name>faultString</name>
               <value><string>Too many parameters.</string></value>
               </member>
            </struct>
         </value>
      </fault>
   </methodResponse>';
$xml = new SimpleXMLElement($responseXML);
echo '<pre>';
print_r($xml);
echo '</pre>';
$fault = $xml->fault->value->struct->member[0]->name;
$faultValue = $xml->fault->value->struct->member[0]->value->int;

echo $fault , '<br />' , $faultValue;
--- End code ---
[/code]

Now it will output

--- Code: ---faultCode
4

--- End code ---


Certainly this way I can get value and using conditions , I can get to know what was response but issue is that node structure changes from service to service, sometimes there is no <fault> code at all, sometimes nesting structure is little different. Basically I need to find if response xml has "faultCode" or  "Code" , then what is in next node which contains real faultcode, same goes with FaultString, I need to find if it has node with value faultstring and then what is value?

Navigation

[0] Message Index

Go to full version