問題描述
我的目標是能夠創建一個包含如下項目的soap請求:
My goal is to be able to create a soap request that can contain items like so:
<flexFields>
<names>
<names>IAG Group</names>
<names>Ticket #</names>
</names>
</flexFields>
然而,我能想到的soapvar 和soapparam 的每一個組合都使我無法復制嵌套的名稱"標簽.我可以像這樣獲得 1 個子標簽:
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:
$flexFields = array(
'names'=> new SoapVar(
new SoapVar(array('names'=>'IAG Group'),SOAP_ENC_OBJECT),
SOAP_ENC_OBJECT)
);
這會產生:
<flexFields xsi:type="ns2:SoapNamedValues">
<names xsi:type="names">
<names xsi:type="xsd:string">IAG Group</names>
</names>
</flexFields>
但是,如果我使用 SOAP_ENC_OBJECT,我為使名稱標簽重復所做的任何嘗試都會生成一個可怕的 BOGUS 元素,或者如果我使用 SOAP_ENC_ARRAY,則將每個項目都包裝在另一個項目"元素中,這也是不可取的.
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.
我知道我可以手動創建我想要的內容并使用 XSD_ANYXML 加載它,但這已經接近違背使用 SOAP 庫的目的了.
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.
誰能提供一個示例,說明如何完美平衡 soapvar/soapparam + 數組嵌套以使其實際工作?還是我在嘗試使用 PHP 的 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?
推薦答案
我也遇到了 BOGUS 標簽問題.我的解決方案涉及使用 ArrayObject 代替數組原語.然后所有對象都轉換為 SoapVar 對象.看起來soap 庫真的想處理無處不在的對象.我在這里有一個更完整的文章:
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:
http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html
這篇關于SoapVar/Param 和 SOAP 中嵌套的重復元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!