PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a SOAP request logger which logs all SOAP requests/responses being made on the system. What I want to do is extract the function name being called and the params passed to it. The following is an example XML Request:
As you can see the "<env:Body>" tag contains everything what I need to extract. "<ns1:make_proxy_payment>" tag contains the function name and the sub-elements contains the function params. What I have so far is:
Before I get to the payment_id, I need to know what function was called. Each request could be a different function. It would be good if I could automate the process of "finding" which function was called and their params and values. That way in the future I don't have to maintain a case statement for each function list.
So basically how do I extract the value "make_proxy_payment" and the "payment_id" (and its value). etc.
foreach ($body->children() as $child)
{
if ($child->getName()=="make_proxy_payment") .....
}
I can't remember how simplexml handles namespaces... so getName() may return either "make_proxy_payment" or "ns1:make_proxy_payment". You'll have to test it to find out.
$xml_string = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>PHP: Behind the Parser</title>
<characters>
<character>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
</character>
<character>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
</character>
</characters>
<plot>
So, this language. It is like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<great-lines>
<line>PHP solves all my web problems</line>
</great-lines>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
$xml = new SimpleXMLElement($xml_string);
print_r($xml);
and the documentation follows it up with:
Return Values
If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.