PHP SOAP服务器返回没​​有标签的XML

时间:2016-10-07 10:15:47

标签: php xml soap server tags

我有以下php服务器代码:

$xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$root = "Data";
$warmdata = "WarmData";
$brinedata = "BrineData";
$permindata = "PerMinData";
$xml .= "<$root>";
    $xml .= "<$warmdata>";
        foreach($result as $row)
        {
            $xml .= "<WarmIn>";
            $xml .= $row['value'] . " " . $row['time'];
            $xml .= "</WarmIn>";
        }

        foreach($result2 as $row)
        {
            $xml .= "<WarmOut>";
            $xml .= $row['value'] . " " . $row['time'];
            $xml .= "</WarmOut>";
        }
    $xml .= "</$warmdata>";

    $xml .= "<$brinedata>";
        foreach($result3 as $row)
        {
            $xml .= "<BrineIn>";
            $xml .= $row['value'] . " " . $row['time'];
            $xml .= "</BrineIn>";
        }

        foreach($result4 as $row)
        {
            $xml .= "<BrineOut>";
            $xml .= $row['value'] . " " . $row['time'];
            $xml .= "</BrineOut>";
        }
    $xml .= "</$brinedata>";

    $xml .= "<$permindata>";
        foreach($result5 as $row)
        {
            $xml .= "<WarmPerMin>";
            $xml .= $row['value'] . " " . $row['time'];
            $xml .= "</WarmPerMin>";
        }

        foreach($result6 as $row)
        {
            $xml .= "<BrinePerMin>";
            $xml .= $row['value'] . " " . $row['time'];
            $xml .= "</BrinePerMin>";
        }
    $xml .= "</$permindata>";
$xml .= "</$root>";

header ("Content-Type:text/xml");
return $xml;

$options=array('uri'=>'http://localhost/');
$server = new SoapServer(NULL,$options);
$server->setClass('DBData');
$server->handle();

我正在尝试使用soap客户端获取格式正确的xml输出,但是当我请求xml时,out只包含从单个数据库中检索到的数字,而不包含实际的xml标记。 我怎么能修改它所以我会在输出中有标签?

1 个答案:

答案 0 :(得分:1)

不允许使用这些标签。你必须写下来:

< replace with &gt;
> replace with &lt;