简体   繁体   English

PHP:在SOAP函数调用中返回XML

[英]PHP: Returning XML in SOAP function call

I want to return the following XML in SOAP when a function is called rather than just a string. 我想在调用一个函数而不是一个字符串时在SOAP中返回以下XML。 There are many different functions that will return an xml formatted this way, is there a way that I can define what a function returns? 有许多不同的函数将返回以这种方式格式化的xml,是否有一种方法可以定义函数返回的内容? Like making my own data type? 喜欢制作自己的数据类型?

<meta>
    <supplier>Amazon.com</supplier>
    <datetime>2010/08/21 14:32:40</datetime>
</meta>
<results>
    <result>
        <manufacturer>Intel</manufacturer>
        <itemno>8236476234</itemno>
        <prices>
            <price>
                <quantity>10</quantity>
                <cost>$1.20</cost>
            </price>
            <price>
                <quantity>100</quantity>
                <cost>$0.80</cost>
            </price>
        </prices>
    </result>
    <result> ... </result>
</results>

The best way is to put your result in an array and then convert it to XML . 最好的方法是将结果放入array ,然后将其转换为XML Here is a ready made script for that: 这是一个现成的脚本:

http://rssphp.net/examples/convert_array_to_xml/ http://rssphp.net/examples/convert_array_to_xml/

It converts almost any kind of associative array to full formed XML. 它将几乎任何类型的关联数组转换为完整的XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM