0

i have the following code.

$stmt = $conn->prepare('SELECT sponsor_path FROM sponsors WHERE conference_id = ?');
$stmt->execute(array($cid));

$sponsorsImg = $stmt->fetchall (PDO::FETCH_OBJ);

$xml_output = "<?xml version=\"1.0\" ?>";
$xml_output .= "<sponsors>";
foreach ($sponsorsImg as $spImg){
    $xml_output .= "<sponsor>\n";
    $xml_output .= "<image>".$spImg->sponsor_path."</image>\n";
    $xml_output .= "</sponsor>\n";
}
$xml_output .= "</sponsors>";

echo $xml_output;

Instead of printing the results in xml format i get only the $spImg->sponsor_path's content in plain text. Any ideas?

1
  • 1
    use right click on html page and show source Commented Oct 24, 2014 at 11:30

1 Answer 1

3

Most browsers will render markup that looks like XML. So it might be the case that the XML that you want is actually produced but not displayed correctly on the browser.

Try the following:

Set the content type before outputting:

header('Content-Type: text/xml');
echo $xml_output;

If the output looks the same, then right click on the page and select view source. You should see your XML markup as intended there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.