I'm trying to create an array in PHP based on an incoming XML message I receive:
<env:Envelope xmlns:soapenc="http://ift.tt/wEYywg" xmlns:xsd="http://ift.tt/tphNwY" xmlns:env="http://ift.tt/sVJIaE" xmlns:xsi="http://ift.tt/ra1lAU">
<env:Header>
</env:Header>
<env:Body env:encodingStyle="http://ift.tt/wEYywg">
<m:getResultsResponse xmlns:m="http://ift.tt/1sTqYEX">
<result xmlns:n1="java:com.medplus.serviceHub.results.webservice" xsi:type="n1:ResultsResponse">
<HL7Messages soapenc:arrayType="xsd:string[1]">
<string xsi:type="xsd:string">MSH|^~\&|LAB|DAL||59498|20130328152600||ORU^R01|80000000000000189794|D|2.3.1</string>
</HL7Messages>
<isMore xsi:type="xsd:boolean">true</isMore>
<requestId xsi:type="xsd:string">9a46bee50a801e1e0b4734f6470ea5dd</requestId>
</result>
</m:getResultsResponse>
</env:Body>
</env:Envelope>
I set $RAWResponse equal to the incoming response above, but when I then try to use this function it doesn't seem to work:
function objectsIntoArray($arrObjData, $arrSkipIndices = array())
{
$arrData = array();
if (is_object($arrObjData)) {
$arrObjData = get_object_vars($arrObjData);
}
if (is_array($arrObjData)) {
foreach ($arrObjData as $index => $value) {
if (is_object($value) || is_array($value)) {
$value = objectsIntoArray($value, $arrSkipIndices);
}
if (in_array($index, $arrSkipIndices)) {
continue;
}
$arrData[$index] = $value;
}
}
return $arrData;
}
$xmlObj = simplexml_load_string($RAWResponse);
$arrXml = objectsIntoArray($xmlObj);
print_r($arrXml);
Any ideas?
Thanks!
NCoder
No comments:
Post a Comment