PHP xml SOAP格式 转换为数组

$xml='<?xml version="1.0" encoding="utf-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <Parameters xmlns="http://hl7.org/fhir" xmlns:sin="http://register.lfwsj.gov.cn/sinosoft_register">
      <parameter>
        <name value="success"/>
        <valueString value="false"/>
      </parameter>
      <parameter>
        <name value="stateCode"/>
        <valueString value="705"/>
      </parameter>
      <parameter>
        <name value="stateInfo"/>
        <valueString value="123456789"/>
      </parameter>
    </Parameters>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
';
$xmlObj = simplexml_load_string($xml);
$xmlObj->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$result = $xmlObj->xpath("soap:Body");
$results = object_to_array($result);

/**
 * 对象 转 数组
 *
 * @param object $obj 对象
 * @return array
 */
function object_to_array($obj) {
    $obj = (array)$obj;
    foreach ($obj as $k => $v) {
        if (gettype($v) == 'resource') {
            return;
        }
        if (gettype($v) == 'object' || gettype($v) == 'array') {
            $obj[$k] = (array)object_to_array($v);
        }
    }
 
    return $obj;
}
	

猜你喜欢

转载自blog.csdn.net/qq_18105691/article/details/83347521
今日推荐