PHP SoapClient 为相同元素创建 XML 引用,使其无法用于服务

2021-12-24 00:00:00 xml php soap

我正在使用 PHP 开发 SOAP 客户端,并且调用可以很好地传递给服务,但存在彼此相同的元素的调用除外.似乎发生这种情况时,而不是创建两个独立但相同的元素,如下所示:

I am working on a SOAP client in PHP, and the calls are going through to the service fine, with the exception of calls where there are elements that are identical to each other. It seems that when this happens, rather than creating two separate but identical elements, like this:

<ns1:someelement>
  <ns1:name>name1</ns1:name>
  <ns1:value>value1</ns1:value>
</ns1:someelement>
<ns1:someelement>
  <ns1:name>name1</ns1:name>
  <ns1:value>value1</ns1:value>
</ns1:someelement>

它坚持只制作元素的一个副本并为其分配一个 ID,并对该元素的任何后续实例使用 href(如下所示),而我正在使用的网络服务不支持(我不支持)知道这是为什么,但这并不重要,因为我无法改变它)

it is insisting on making only one copy of the element and assigning it an ID, and using href for any subsequent instances of that element (shown below), which is not supported by the webservice I am using (I don't know why this is, but it doesn't really matter because I cannot change it)

<ns1:someelement id="#ref1">
  <ns1:name>name1</ns1:name>
  <ns1:value>value1</ns1:value>
</ns1:someelement>
<ns1:someelement href="#ref1" />

所以我的问题是如何强制 XML 包含完整的重复元素,而不是使用 hrefs/ids.我检查了 PHP SoapClient 的文档以获取选项或类似内容,但找不到任何内容.任何帮助或建议将不胜感激.谢谢.

So my question is how might I force the XML to come out with the duplicate elements included in full, rather than them using hrefs/ids. I checked the docs for PHP SoapClient for an option or something of the sort, but couldn't find anything. Any help or advice would be greatly appreciated. Thanks.

推荐答案

SoapClient 仅在您在多个 XML 节点上使用同一对象时才进行引用.如果您不想要引用,请为每个位置创建一个新对象.

SoapClient makes a reference only when you use the same object on multiple XML nodes. Make for each place a new object if you do not want the references.

相关文章