0

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://localhost/Quiz/images/".$row[7];
}
else
{
$path="";
}
}
}
$xml_output .= "</questions>\n";
echo $xml_output;
?>
3
  • 3
    Can you post the source of the generated XML from the client side please?
    – 93196.93
    Jul 27, 2011 at 13:54
  • 1
    If $result is false then </questions>
    – Steve-o
    Jul 27, 2011 at 14:05
  • You might be looking for XMLWriter.
    – hakre
    Jul 27, 2011 at 14:06

3 Answers 3

1

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.

0

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

2
  • Also, you don't need any new lines ("\n") for the XML to be correct. You can have an entire XML documment in one line and stil be 100% valid. You can use the new lines only if you want the XML to look better visually for a person.
    – AlexL
    Jul 27, 2011 at 14:02
  • New line characters can be used inside the XML but never as the first character or the last character in the XML
    – AlexL
    Sep 13, 2011 at 9:59
-1

Change

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

To

$xml_output .= "</questions>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.