GreenRover
GreenRover

Reputation: 1516

PHP: Soap Client xmlattribute

I have try to use an php soap client.

But the SOAP XML needs to contain an XML attribute like "opCode=EQ" this example:

     <ws:Query>
        ....
        <com:Properties>
           <com:xx>yy</com:xx>
           <com:ab>cc</com:ab>
        </com:Properties>
        <com:QueryCondition>
           <com:CmpOp opCode="EQ">
              <com:Property>FolderName</com:Property>
              <com:Value>AB028</com:Value>
           </com:CmpOp>
        </com:QueryCondition>
     </ws:Query>

I try to read this by using this code:

$this->client = new SOAPClient(__DIR__ . '/WSDL.XML', array(
        'trace' => 1, 
        'exception' => 1
    ));

$this->client->query((object) array(
        // ..
        'Properties' => (object) array(
            'xx' => 'yy',
            'ab' => 'cc'
        ),
        'QueryCondition' => (object) array(
            'CmpOp' => (object) array(
                'opCode' => 'EQ',
                '_' => (object) array(
                    'Property' => 'FolderName',
                    'Value' => 'AB028',
                ),
            ),
        ),
    ));

But this results in:

    <com:QueryCondition>
       <com:CmpOp>
          <com:Property>FolderName</com:Property>
          <com:Value>AB028</com:Value>
       </com:CmpOp>
       </com:_><com:opCode>EQ</com:opCode></com:_>
    </com:QueryCondition>

Can someone tell me the right syntax?

Upvotes: 1

Views: 117

Answers (1)

GreenRover
GreenRover

Reputation: 1516

All that stuff with underline i found in the internet dosent work.

The only working solution i found is:

$this->client->query((object) array(
        // ..
        'Properties' => (object) array(
            'xx' => 'yy',
            'ab' => 'cc'
        ),
        'QueryCondition' => (object) array(
            'CmpOp' => new SoapVar(
                        '<CmpOp opCode="EQ">' .
                            '<Property>FolderName</Property>' . 
                            '<Value>' . htmlspecialchars('AB028'). '</Value>' . 
                        '</CmpOp>',
                    XSD_ANYXML
                )
            ),
        ),
    ));

Upvotes: 1

Related Questions