soap服务器读取XML属性


zend soap server reading xml attributes

需要Zend_Soap_Server的帮助。我正在构建一个web服务来处理某些固定的xml文档。问题是一些节点在属性中有数据集:

<Car_Interest xmlns="http://schemas.multi-mit.com/DataFormat">
   <Model_Of_Interest Code="SOME CAR" />
   <Estimated_Purchase_Date>20190509</Estimated_Purchase_Date>
</Car_Interest>

当我将soap请求传递给服务器时,我的处理程序类接收到一个包含所有节点和值的stdObject,但不包含属性。这是我的控制器:

indexAction(){
    $server = new Zend_Soap_Server(null,
        array('uri' => 'http://some.url/index/soap'));
    // set SOAP service class
    $server->setClass('Module_Model_SoapHandler');
    // handle request
    $server->handle($data);
}

到目前为止的处理程序:

class Testdrive_Model_SoapHandler {
    public function saveSubmission($data)
    {
        return $data;
    }
...

正确传入$data变量(stdObject),但不包含属性值(节点Model_Of_Interest的属性Code)。我错过什么了吗?

我刚刚遇到这个问题,找到了这个解决方案…

Php Soap Server(底层)不解析属性

使用DOMDocument解析数据以获取所有属性

$dom = new 'DOMDocument;
$dom->loadXML(file_get_contents("php://input"));

转换为数组以方便使用…

什么是最好的php DOM 2数组函数?

结果

  "Car_Interest" => array:2 [
    "Model_Of_Interest" => array:1 [
      "@attributes" => array:1 [
        "Code" => "SOME CAR"
      ]
    ]
    "Estimated_Purchase_Date" => "20190509"
  ]