php - Parse CURL SOAP response -


i accessing soap server via curl (its way php connect). response i'm receiving:

<s:envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> <s:header>     <a:action s:mustunderstand="1">publicapi/ipropertyservice/createpropertyresponse</a:action> </s:header> <s:body>     <createpropertyresponse xmlns="publicapi">         <createpropertyresult xmlns:b="http://schemas.datacontract.org/2004/07/efxframework.publicapi.property" xmlns:i="http://www.w3.org/2001/xmlschema-instance">             <message xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">successfully completed operation</message>             <result xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">0</result>             <transactiondate xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">2013-05-15t04:07:48.6565312z</transactiondate>             <b:propertyid>55</b:propertyid>         </createpropertyresult>     </createpropertyresponse> </s:body> 

i'm trying pull content of:

<message xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">successfully completed operation</message> <result xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">0</result> <b:propertyid>55</b:propertyid> 

but can't figure out how parse it. i've tried "simplexml_load_string" put throws bunch of errors such "namespace warning : xmlns: uri publicapi not absolute"

any suggestions?

a bit of hack, if format of response same, following might work you:

?php // message come somewhere else; hard code test expression follows: $msg='<s:envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> <s:header>     <a:action s:mustunderstand="1">publicapi/ipropertyservice/createpropertyresponse</a:action> </s:header> <s:body>     <createpropertyresponse xmlns="publicapi">         <createpropertyresult xmlns:b="http://schemas.datacontract.org/2004/07/efxframework.publicapi.property" xmlns:i="http://www.w3.org/2001/xmlschema-instance">             <message xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">successfully completed operation</message>             <result xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">0</result>             <transactiondate xmlns="http://schemas.datacontract.org/2004/07/efxframework.publicapi">2013-05-15t04:07:48.6565312z</transactiondate>             <b:propertyid>55</b:propertyid>         </createpropertyresult>     </createpropertyresponse> </s:body>';  // here comes actual parsing: $reg1='/<message [^>]*>([^<]*)</'; $reg2='/<result [^>]*>([^<]*)</'; preg_match($reg1, $msg, $m); print "message: ". $m[1]."\n"; preg_match($reg2, $msg, $m); print "result: ".$m[1]."\n"; ?> 

result of above:

message: completed operation result: 0 

explanation:

[^>]*> : "any number of characters not >, followed >

([^<]*) : "'capture' characters not <. return them in $m[1]

i hope helps.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -