Author Topic: How to parse XML-Rpc Ping request in PHP  (Read 10645 times)

girish baghel

  • Newbie
  • *
  • Posts: 2
How to parse XML-Rpc Ping request in PHP
« on: June 23, 2012, 06:50:41 AM »
I have problem in parsing xml-RPC response,
(say we have following string) 
Code: [Select]
$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;
[/code]

Now it will output
Code: [Select]
faultCode
4


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?

 

X

Do you know?

IfandBut.com is place where you can meet serious webmasters and make new ties to grow your business.
Join Now!