XML with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

XML with PHP

Post by Aravinthan »

Hi guys,
I want to read a MYSQL data and then output it as a XML file....

Easy right?

Well, I reduced the coding to this simplest thing:

Code: Select all

 
<?php
 
header("Content-type: text/xml"); 
 
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
 
echo "<slide_show>";
    echo "<photo>./images/DCP_0730.jpg</photo>";
echo "</slide_show>";
 
?>
 
But it still doesnt work.

In Firefox I get:
XML Parsing Error: not well-formed
Location: http://liguedhockeysimule.x10hosting.com/default.xml
Line Number 7, Column 7:
echo "<slide_show>";
------^
In IE 8 I get:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 'http://liguedhockeysimule.x10hosting.com/default.xml'....

echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
-------------------------------------------------^
I looked and looked, still cant seem to find the error....

Thanks for your help,
Ara
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: XML with PHP

Post by Aravinthan »

I am pretty sure it is really a dumb mistake that I made somewher :oops:

But I cant find it,
I changed the code to single qutoes, back to to double....
But I guess I need to :banghead: or something....
You can't imagine how stupid I feel lol
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: XML with PHP

Post by cpetercarter »

You have a space immediately before the final ? in the declaration line. Try removing it.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: XML with PHP

Post by Eran »

The problem is the whitespace at the beginning of the file. You need to remove all whitespace before the opening PHP tag.
Post Reply