Page 1 of 1

mysql -> php -> xml

Posted: Mon Nov 08, 2004 8:53 am
by timtom
Hi

I need to create a xml feed from a mysql db, via php.

I wanted the feed to be dynamic and always updated, so I figured just to write the feed directly to the browser (echo "<element>data</element>").

Loading the dynamic feed (xmlfeed.php) in the browser works fine (the output is the correct data), but trying to parse the same file as xml with php, givs me this xml error: "XML error: not well-formed (invalid token) at line 1".

If I just write data to a file - "feed.xml" (fwrite ($fp, "<element>data</element>")) and then parsing it, it works fine....

So I am thinking maybee the XML error is a result of trying to open the file "xmlfeed.php"as an xml file and this produces the error because the output has'nt started yet...?

So is the only way to do this, to have a cron job producing the xml feed? or is there something I have overlooked or a workaroud?

Any help or comments will be much appreciated.

Have a great one.

Posted: Mon Nov 08, 2004 9:19 am
by Weirdan
what does your generated output look like when you view it via browser's 'View source' command? Post it here (do not forget to wrap it in

Code: Select all

tags).

Posted: Tue Nov 09, 2004 2:48 am
by timtom
Like this:

Code: Select all

<boligdata>
	<B URL="http://www.interbo.dk/boligsag.php?sag=21" Beskrivelse="Ejendommen har netop fået fjernet sin bopælspligt hvilket gør det særdeles attraktivt for den kræsne køber der ønsker sig et godt gedigent helårshus med sommerhus status, på måske Danmarks bedste beliggenhed skråt overfor Trouville. Huset er p.t.under modernisering og sælger har i den forbindelse undladt at opføre et nyt badeværelse på 1 sal så den nye ejer kan have indflydelse på udformningen. Huset er smukt placeret på grunden med stor solrig træterrasse. Endvidere er der garage og udhus.
Huset indeholder: Entré, stor spisestue med frilagte bjælker, adgang til havestue med småsprosset ruder, dagligstue og flot trappe til 1. sal. Landligt køkken med spise plads og adgang til kombineret fyrrum, bryggers og badeværelse.
 Endvidere er der fra køkkenet udgang til flot træterrasse. 1. sal indeholder stort badeværelse samt sep. toilet og 2 gode værelser. Flot master-bedroom med skabsvæg og udgang til altan.
Huset har været en del af Trouville og har i den forbindelse været brugt som helårsrecidens for Hotellets direktør
i mange år." BoligType="Villa" Gade="Kystvej 21 3100 Hornbæk" Postnr="3100" BoligM2="174" HaveM2="709" Kontantpris="8500000" Udbetaling="3489995" BruttoPris="31709" NettoPris="27110">
  <BA email="" />
</B>

Posted: Tue Nov 09, 2004 6:58 am
by Weirdan
it isn't well-formed xml. <boligdata> not closed. Perhaps you will need to state the encoding (usually UTF-8) as well.

Posted: Wed Dec 01, 2004 5:45 am
by timtom
sorry - I omitted the closing tag for <boligdata>. But it is in the end of the output (ie. <boligdata><b .......><ba></ba></b><b .......><ba></ba></b><b .......><ba></ba></b></boligdata>). I have also tried utf-8 encoding, but it makes no difference.