php SoapVar/Param 和 SOAP 中嵌套的重复元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4855677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SoapVar/Param and nested, repeated elements in SOAP
提问by mainegreen
My goal is to be able to create a soap request that can contain items like so:
我的目标是能够创建一个包含如下项目的soap请求:
<flexFields>
<names>
<names>IAG Group</names>
<names>Ticket #</names>
</names>
</flexFields>
However, every combination of soapvar and soapparam I've been able to think up either makes it impossible for me to duplicate the nested 'names' tag. I can get 1 sub tag like so:
但是,我能够想到的soapvar 和soapparam 的每种组合都使我无法复制嵌套的“名称”标签。我可以像这样获得 1 个子标签:
$flexFields = array(
'names'=> new SoapVar(
new SoapVar(array('names'=>'IAG Group'),SOAP_ENC_OBJECT),
SOAP_ENC_OBJECT)
);
This generates:
这会产生:
<flexFields xsi:type="ns2:SoapNamedValues">
<names xsi:type="names">
<names xsi:type="xsd:string">IAG Group</names>
</names>
</flexFields>
But any attempt I make to get the names tag to repeat either generates a dreaded BOGUS element if I use SOAP_ENC_OBJECT, or wraps every item in another 'item' element if I use SOAP_ENC_ARRAY, which is also not desirable.
但是,如果我使用 SOAP_ENC_OBJECT,我为使名称标签重复所做的任何尝试都会生成一个可怕的 BOGUS 元素,或者如果我使用 SOAP_ENC_ARRAY,则将每个项目都包装在另一个“项目”元素中,这也是不可取的。
I know I could just manually create what I want and load it with XSD_ANYXML, but that is getting close to the line of defeating the purpose of using the SOAP library.
我知道我可以手动创建我想要的内容并使用 XSD_ANYXML 加载它,但这已经接近违背使用 SOAP 库的目的了。
Can anyone provide an example of just how to perfectly balance the soapvar/soapparam + array nesting to get this to actually work? Or am I attempting the impossible with PHP's SOAP library?
谁能提供一个示例,说明如何完美平衡soapvar/soapparam + 数组嵌套以使其实际工作?还是我在尝试使用 PHP 的 SOAP 库做不可能的事?
回答by Matttrach
I have a similar problem, try this:
我有类似的问题,试试这个:
$Names=array();
$Names[]=new SoapVar("IAG Group",XSD_STRING,null,null,'names');
$Names[]=new SoapVar("Ticket #",XSD_STRING,null,null,'names');
$BigNames=new SoapVar($Names,SOAP_ENC_OBJECT,null,null,'Names');
This creates and array of of SoapVar objects ($Names) and places them in the BigNames object, creating an output like this:
这将创建 SoapVar 对象 ($Names) 数组并将它们放置在 BigNames 对象中,创建如下输出:
<Names>
<names>IAG Group</names>
<names>Ticket #</names>
</Names>
You can then create another SoapVar object for FlexFields, but for some reason you can't place a SoapVar object directly into another, it has to be stored in an array...
然后,您可以为 FlexFields 创建另一个 SoapVar 对象,但由于某些原因,您不能将 SoapVar 对象直接放入另一个对象中,它必须存储在数组中...
I want to do this:
我想做这个:
$FlexFields=new SoapVar($BigNames,SOAP_ENC_OBJECT,null,null,'FlexFields');
This works:
这有效:
$FF=array($BigNames);
$FlexFields=new SoapVar($FF,SOAP_ENC_OBJECT,null,null,'FlexFields');
回答by Mark F
I ran into the BOGUS tag problem also. My solution involved using an ArrayObject in place of array primitives. The objects are all then converted to SoapVar objects. It seems the soap library really wants to deal with objects everywhere. I have a more complete writeup here:
我也遇到了 BOGUS 标签问题。我的解决方案涉及使用 ArrayObject 代替数组原语。然后所有对象都转换为 SoapVar 对象。看起来soap 库真的想处理无处不在的对象。我在这里有一个更完整的文章:
http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html
http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html