Converting php to xml

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
maestro
Forum Newbie
Posts: 6
Joined: Fri Jun 01, 2007 12:49 pm

Converting php to xml

Post by maestro »

Hi everyone ,

i have been trying to convert this code to an xml by using headers but this error keeps occuring

Warning: Cannot modify header information - headers already sent by (output started at /home/other/db2student/labdb224/public_html/xml1.php:1) in /home/other/db2student/labdb224/public_html/xml1.php on line 1

This is the code in php :

Code: Select all

<?php header('Content-Type: text/xml');?>
<?php echo "<?xml version='1.0'?>"?>

<?php echo "<?xml-stylesheet type='text/xsl' href='xsl/projections.xsl'?>"?>

<projections>
<?php

$dbhost = "******";
$dbname = "*****";
$dbuser = "*****";
$dbpass = "*****";


mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$query="SELECT * FROM projections";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {
$movie=mysql_result($result,$i,"movie");
$room_number=mysql_result($result,$i,"room_number");
$start_time=mysql_result($result,$i,"start_time");
$end_time=mysql_result($result,$i,"end_time");
$date=mysql_result($result,$i,"date");
$projectionid=mysql_result($result,$i,"projectionid");


?>
	<projection>
		<titlos> <?php echo $movie; ?> </titlos>
		<room_number> <?php echo $room_number; ?> </room_number>
		<start_time> <?php echo $start_time; ?> </start_time>
		<end_time> <?php echo $end_time; ?> </end_time>
		<date> <?php echo  $date; ?> </date>
	</projection>
<?

$i++;
}

?>
</projections>
I would apreciate it if someone could help me ,
thanks in advance :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Converting php to xml

Post by superdezign »

... Is there any whitespace before you attempt to change the header information?
maestro
Forum Newbie
Posts: 6
Joined: Fri Jun 01, 2007 12:49 pm

Post by maestro »

nope :/
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's something there. Whether you may see it or not, there is. I would bet it's a BOM (byte-order marker.)
maestro
Forum Newbie
Posts: 6
Joined: Fri Jun 01, 2007 12:49 pm

Post by maestro »

Well this is the code the exact way its executed :

http://www.mediafire.com/?3txymfnczfg
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Yeah, there's extra.. something at the start of your file, but you can't touch it through a regular editor.

What I did was copied all of the text up to the first character, deleted that file, and created a new one, then pasted the code.

Try Visual Studio, Dreamweaver, or Notepad++ for the best results.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

From my experience, most users get a hidden character as a result of using Dreamweaver :wink:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Jcart wrote:From my experience, most users get hidden character as a result of using Dreamweaver :wink:
Yeah, Dreamweaver has multiple ways of creating files that give different results. If you do it by right-clicking in the file browser, and creating new file, you should be fine.
maestro
Forum Newbie
Posts: 6
Joined: Fri Jun 01, 2007 12:49 pm

Post by maestro »

Thnx for help everyone , saved the file in ANSI through notepad and it works :D
maestro
Forum Newbie
Posts: 6
Joined: Fri Jun 01, 2007 12:49 pm

Post by maestro »

The only problem i have now is that an error occurs when trying to parse data with "&".
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Umm... Not sure why. Try to str_replace & with &.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post by pedrotuga »

maestro wrote:The only problem i have now is that an error occurs when trying to parse data with "&".
post the error report please
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://en.wikipedia.org/wiki/Xml wrote:An entity reference is a placeholder that represents that entity. It consists of the entity's name preceded by an ampersand ("&") and followed by a semicolon (";"). XML has five predeclared entities:

* & (&, ampersand)
* < (<, less than)
* > (>, greater than)
* &apos; (', apostrophe)
* " (", quotation mark)
Replace all those characters by their entity representation in normal data nodes.
maestro
Forum Newbie
Posts: 6
Joined: Fri Jun 01, 2007 12:49 pm

Post by maestro »

Thanks for the help everyone :wink:
Post Reply