nusoap 中的重复标签

发布于 2024-07-08 10:56:46 字数 714 浏览 12 评论 0原文

我正在使用 nusoap 连接到肥皂网络服务。 该类发送到服务的 xml 是从数组构造的,即:

$params = array("param1" => "value1", "param2" => "value1");
$client->call('HelloWorld', $params, 'namespace', 'SOAPAction');

这工作正常。 多维数组还可以构造一个很好的嵌套 xml 消息。

当我需要两个同名的标签时遇到问题:

<items>
   <item>value 1</item>
   <item>value 2</item>
</item>

$params = array("items" => array("item" => "value 1", "item" => "value 2"));

数组中的第二项覆盖第一项,这会导致:

<items>
   <item>value 2</item>
</item>

如何实现这一点?

I'm using nusoap to connect to a soap webservice. The xml that the class sends to the service is constructed from an array, ie:

$params = array("param1" => "value1", "param2" => "value1");
$client->call('HelloWorld', $params, 'namespace', 'SOAPAction');

This works fine. A multidimensional array also constructs a nice nested xml message.

I encounter a problem when i need two tags with the same name:

<items>
   <item>value 1</item>
   <item>value 2</item>
</item>

$params = array("items" => array("item" => "value 1", "item" => "value 2"));

The second item in the array overwrites the first which results in:

<items>
   <item>value 2</item>
</item>

How can achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我只土不豪 2024-07-15 10:56:46

问题在于内部 array()

$test_array = array("item" => "value 1", "item" => "value 2");

创建一个具有单个键(“item”)的数组。

尝试一下,看看它是否有效:

$params = array("items" => array("item" => array("value 1", "value 2")));

不过,不能保证...我已经很长时间没有使用过 nusoap,并且这里没有安装 PHP 来测试它。

The problem is with the inner array()

$test_array = array("item" => "value 1", "item" => "value 2");

creates an array with a single key ("item").

Try this and see if it works:

$params = array("items" => array("item" => array("value 1", "value 2")));

No guarantees, though... I haven't used nusoap in a long time and don't have PHP installed here to test it.

椒妓 2024-07-15 10:56:46

这很奇怪,因为 method:

$params = array('items' => array('item' => array('value1', 'value2')))
$client->call( 'action', $params );

对我有效。 正如所解释的
在此链接

也许您需要更新版本的 nusoap ?

This is strange because, method:

$params = array('items' => array('item' => array('value1', 'value2')))
$client->call( 'action', $params );

works form me. As explained
in this link

Maybe you need newer version of nusoap?

猫七 2024-07-15 10:56:46

我们通过将字符串而不是数组传递给 nusoap 调用函数解决了这个问题。
请检查下面的链接
http://fundaa.com/php/solved-duplicate-tags-in-努肥皂/

we have solved this problem by passing string instead of array to nusoap call function.
please check link below
http://fundaa.com/php/solved-duplicate-tags-in-nusoap/

三生池水覆流年 2024-07-15 10:56:46

你的核心问题是你正在编写无效的 PHP 代码

$x = array("items" => array("item" => "value 1", "item" => "value 2")); 
var_dump($x);

array(1) {
  ["items"]=>
  array(1) {
    ["item"]=>
    string(7) "value 2"
  }
}

Which of course won't work,因为它的同义词是

 $x = array(); 
 $x['items'] = array(); 
 $x['items']['item']='value 1'; 
 $x['items']['item']='value 2'; 

which of course won't work。

你最好的选择是使用

 array("items"=>array( "value1","value2") );  

并希望数字键能够“工作”
或者

 array("items"=>array("item"=>array("value1","value2"))) 

万一有这样的倾向。

此外

Looking through the examples on sourceforge, it would appear this is valid syntax:

$params = '<person xsi:type="tns:Person"><firstname xsi:type="xsd:string">Willi</firstname><age xsi:type="xsd:int">22</age><gender xsi:type="xsd:string">male</gender></person>';
$result = $client->call('hello', $params);

http://nusoap.cvs.sourceforge.net/ viewvc/checkout/nusoap/samples/wsdlclient3b.php

这个显示使用非键控(即:数字)数组作为输入源:
http://nusoap.cvs.sourceforge.net/ viewvc/结帐/nusoap/samples/wsdlclient4.php

Your core problem is you're writing invalid PHP code

$x = array("items" => array("item" => "value 1", "item" => "value 2")); 
var_dump($x);

array(1) {
  ["items"]=>
  array(1) {
    ["item"]=>
    string(7) "value 2"
  }
}

Which of course wont work, as its synonymous with

 $x = array(); 
 $x['items'] = array(); 
 $x['items']['item']='value 1'; 
 $x['items']['item']='value 2'; 

which of course won't work.

Your best bets are with

 array("items"=>array( "value1","value2") );  

and hoping the numeric keys will "work"
or

 array("items"=>array("item"=>array("value1","value2"))) 

in the event it is so inclined.

Additionally

Looking through the examples on sourceforge, it would appear this is valid syntax:

$params = '<person xsi:type="tns:Person"><firstname xsi:type="xsd:string">Willi</firstname><age xsi:type="xsd:int">22</age><gender xsi:type="xsd:string">male</gender></person>';
$result = $client->call('hello', $params);

http://nusoap.cvs.sourceforge.net/viewvc/checkout/nusoap/samples/wsdlclient3b.php

This one shows using an un-keyed ( ie: numeric ) array as an input source:
http://nusoap.cvs.sourceforge.net/viewvc/checkout/nusoap/samples/wsdlclient4.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文