使用 PHP 创建 SOAP 请求 - 如何向 XML 标记添加属性? [英] Creating a SOAP request with PHP - how do I add attributes to the XML tags?

查看:31
本文介绍了使用 PHP 创建 SOAP 请求 - 如何向 XML 标记添加属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 SOAP 调用中生成以下 XML:

I am trying to generate the following XML in my SOAP call:

<CResponse>
    <ID>int</ID>
    <Response Action="Apply">
        <Question ID="$someint">
            <Responses>
                <Response ID="$someotherint" />
                <Response ID="$yetanotherint" />
            </Responses>
        </Question>
    </Response>
</CResponse>

我可以很好地创建大部分调用 - 我终于发现嵌套数组是我的朋友 - 但我不知道如何添加那些 ID="$int"Action="Apply" 属性到各种标签.我确定这很容易,但我就是想不通.

I can create most of the call just fine - I've finally picked up that nested arrays are my friends - but I have no idea how to add those ID="$int" and Action="Apply" attributes to the various tags. I'm sure this is fairly easy, but I just can't figure it out.

TIA.

推荐答案

我不知道 JJ 建议的(有些奇怪的)语法(根据您对问题的重新发布,它似乎不起作用),但是您应该能够通过或多或少手动"使用带有 XSD_ANYXML 编码的 SoapVar 类来构建请求 xml.

I don't know about the (somewhat weird) syntax suggested by JJ (and according to your reposting of the question, it doesn't seem to work), but you should be able to shape your request xml anyway you want by constructing it more or less 'manually' using the SoapVar class with the XSD_ANYXML encoding.

请参阅此用户对 SoapVar 构造函数文档的评论有关如何执行此操作的示例.

See this user comment to the SoapVar Constructor documentation for an example of how to do this.

如果您需要构建的 XML 变得更复杂,请考虑使用 SimpleXML 或 DOMDocument 进行组装,而不是直接编写.

If the XML you need to construct gets more complex, consider using SimpleXML or DOMDocument to assemble it instead of writing it directly.

(我觉得应该没有更简单的方法来做到这一点仍然很奇怪,但到目前为止我还没有找到.)

(It still seems odd to me that there should be no simpler way to do this, but so far I have not found one.)

刚刚在 这个问题中找到了另一个使用 XSD_ANYXML 编码的例子,要求更简单的方法来做到这一点.不幸的是,到目前为止还没有人想出更简单的方法:/

Just found another example using the XSD_ANYXML encoding in this question asking for a simpler way to do it. Unfortunately no one came up with a simpler way so far :/

这篇关于使用 PHP 创建 SOAP 请求 - 如何向 XML 标记添加属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆