【问题标题】:Extra content at the end of the document (xml)(php)文档末尾的额外内容 (xml)(php)
【发布时间】:2017-04-05 18:43:15
【问题描述】:

我想显示 mysql 数据库中的所有数据并使用 xml 格式。但它显示错误消息“第 2 行第 205 列的错误:文档末尾的额外内容” 怎么解决?

<?php
    extract($_REQUEST);
    include ('connect.php');

    if ($result_no = $conn->query("SELECT * FROM enxml")){

    while ($row_no = $result_no->fetch_object()){

    $xml = '';
    $xml .= '<stationList>';
    $xml .= '<station no="' . $row_no->no . '">' ;
    $xml .= '<location>'. $row_no->location .'</location>';
    $xml .= '<lat>'.$row_no->lat.'</lat>';
    $xml .= '<lng>'.$row_no->lng.'</lng>';
    $xml .= '<type>'.$row_no->type.'</type>';
    $xml .= '<districtL>'.$row_no->districtL.'</districtL>';
    $xml .= '<districtS>'.$row_no->districtS.'</districtS>';
    $xml .= '<address>'.$row_no->address.'</address>';
    $xml .= '<provider>'.$row_no->provider.'</provider>';
    $xml .= '<parkingNo>'.$row_no->parkingNo.'</parkingNo>';
    $xml .= '<img>'.$row_no->img.'</img>';
    $xml .= '</station>';
    $xml .= '</stationList>';


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

    ?>

【问题讨论】:

    标签: php xml mysqli


    【解决方案1】:

    xml 中应该只有一个根元素。你现在有很多。将&lt;stationList&gt; 移出while 循环和echo xml 在while 循环之后:

    $xml = '';
    $xml .= '<stationList>';
    while ($row_no = $result_no->fetch_object()){
        $xml .= '<station no="' . $row_no->no . '">' ;
        $xml .= '<location>'. $row_no->location .'</location>';
        $xml .= '<lat>'.$row_no->lat.'</lat>';
        $xml .= '<lng>'.$row_no->lng.'</lng>';
        $xml .= '<type>'.$row_no->type.'</type>';
        $xml .= '<districtL>'.$row_no->districtL.'</districtL>';
        $xml .= '<districtS>'.$row_no->districtS.'</districtS>';
        $xml .= '<address>'.$row_no->address.'</address>';
        $xml .= '<provider>'.$row_no->provider.'</provider>';
        $xml .= '<parkingNo>'.$row_no->parkingNo.'</parkingNo>';
        $xml .= '<img>'.$row_no->img.'</img>';
        $xml .= '</station>';
    }
    $xml .= '</stationList>';
    
    header("Content-Type:text/xml");
    echo $xml;
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多