zend soap server reading xml attributes

387 views Asked by At

need some help with Zend_Soap_Server. I am building a webservice to proccess certain fixed xml documents. The issue is that some of the nodes have data set in attributes:

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

When I pass the soap request in to server my handler class receives a stdObject with all nodes and values, but does not contain attributes. Here is my controller:

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);
}

And the handler so far:

class Testdrive_Model_SoapHandler {

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

The $data variable is passed in correctly (stdObject), but it does not include attribute values (arrtibute Code of node Model_Of_Interest . Am I missing something?

1

There are 1 answers

1
Artistan On

I just had this issue and found this solution...

Php Soap Server (under the hood) does not parse out the attributes.

parse data with DOMDocument to get all attributes

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

convert to array for easy use...

What is the best php DOM 2 Array function?

results

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