PHP:Soap Client xmlattribute

时间:2015-05-07 11:06:36

标签: php soap-client xml-attribute

我尝试使用php soap客户端。

但SOAP XML需要包含一个XML属性,例如“opCode = EQ”这个例子:

     <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>

我尝试使用此代码阅读此内容:

$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',
                ),
            ),
        ),
    ));

但结果是:

    <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>

有人可以告诉我正确的语法吗?

1 个答案:

答案 0 :(得分:1)

所有那些带有下划线的东西我都在互联网上找到了工作。

我找到的唯一可行解决方案是:

$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
                )
            ),
        ),
    ));