开发者

xml parsing in php webservice

开发者 https://www.devze.com 2023-03-23 01:22 出处:网络
i have write php web service using xml parsing but it displays error on line 3 at column 1: Extra content at the end of the document

i have write php web service using xml parsing but it displays

  error on line 3 at column 1: Extra content at the end of the document

Below is a rendering of the page up to the first error.

my code is

<?php
header("Content-type:text/xml");
require 'dbconnect.php';
$query="SELECT * FROM `tbl_quiz_question` where QuestionType='$questiontype'";
$result=mysql_query($query);
if($result)
{
$xml_output ="<?xml version=\"1.0\"?>\n";
$xml_output .= "<questions>\n";
while($row=mysql_fetch_row($result))
{
if($row[7]!= null)
{
$path="http://loca开发者_开发技巧lhost/Quiz/images/".$row[7];
}
else
{
$path="";
}
}
}
$xml_output .= "</questions>\n";
echo $xml_output;
?>


I am not sure if I am missing something but, it seems like you are not populating $xml_output inside the database loop at all.

Anyway, if you plan on using your existing code, pass all your data through htmlentities to make is suitable for XML output.

If you are willing to go a step further, use the Document Object Model to generate the XML. It'll take care of everything for you.


Remove the "\n" at the end (after </questions>).


Change

$xml_output .= "</questions>\n";

To

$xml_output .= "</questions>";
0

精彩评论

暂无评论...
验证码 换一张
取 消