Page 1 of 1

generate a dynamic XML response from a PHP script

Posted: Sun Aug 19, 2007 8:19 pm
by itp
I am trying to generate a dynamic XML response from a PHP script. Based on what I have learned about the process so far, it is my understanding that the following segment of code should generate a XML response and will appear as an XML tree in when viewed in Internet Explorer showing XML tags and content.

However what I get looks like a regular HTML page.

If I save the document to a file with .xml extention it is viewed as a tree in IE, however when generated dynamically it looks like a regular html document.

I hope I am expressing myself clearly. There are alot of new concepts here for me. 8O


Here is a simplified example.

Code: Select all

<?php 
header('Content-Type: text/xml; charset=UTF-8'); 
header('Content-Disposition: inline; filename="test.xml"'); 
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo <<<BODY
<invoice>
<to>12345</to> 
<from>TP937373</from> 
<heading>Invoice Header</heading> 
<body>Invoice Detail</body> 
</invoice>
BODY;
?>

Re: generate a dynamic XML response from a PHP script

Posted: Sun Aug 19, 2007 9:43 pm
by Christopher
You might want to try:

Code: Select all

<?php 
header('Content-Type: text/xml; charset=UTF-8'); 
header('Content-Disposition: inline; filename="test.xml"'); 
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo <<<BODY
<?xml version="1.0"?>
<invoice>
<to>12345</to> 
<from>TP937373</from> 
<heading>Invoice Header</heading> 
<body>Invoice Detail</body> 
</invoice>
BODY;
?>

Posted: Mon Aug 20, 2007 7:32 am
by volka

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
header('Content-Type: text/xml; charset=UTF-8');
header('Content-Disposition: inline; filename="test.xml"'); 

echo '<?xml version="1.0" encoding="UTF-8"?>
<invoice>
 <to>12345</to>
 <from>TP937373</from>
 <heading>Invoice Header</heading>
 <body>Invoice Detail</body>
</invoice>';
?>
works fine for me. Firefox even honors the filename="test.xml" directive, IE doesn't