Anyone who can answer my question deserves a BIG FAT GOLD MEDAL OF AWESOMENESS!
I'm trying to get the contents of a MySQL table into a nice, easy XML format. I'm running a bit of PHP which works great and I can see XML (Good times). However, in the MySQL table there are a couple of fields which are populated with non-encoded HTML table code. I'm wrapping each field value that I get inside CDATA tags, I've made sure that the xml tags are being closed, but I'm wondering if I'm missing something because it's erroring and I can't see why (Bad times). It looked fine to me, so I tried to open this in Excel (as that's how the client will see it) it claimed that the start tag of "package" was matched with an end tag of "long_description".
http://www.shavesgreensafaris.com/display.php is the page that I'm working on so you can see the data there.
This is the code I'm using...
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$root_element = "packages";
$xml .= "<$root_element>";
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml .= "<package>";
//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= "<$key>";
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= "<![CDATA[$value]]>";
//and close the element
$xml .= "</$key>";
}
$xml.="</package>";
}
}
//close the root element
$xml .= "</$root_element>";
//send the xml header to the browser
header ("Content-Type:text/xml");
//output the XML data
echo $xml;
What ON EARTH am I doing wrong?!
EDIT
OK, so there appears to be something that removes one "<" from a long_description tag around line 310 - you can search in the view source if you want to see it as ">long_description>" - something really weird has happened and the tag isn't properly formed. I wasn't entirely sure HOW this could happen as the code I'm using definitely puts opening and closing angle brackets on all $keys. It only happens once, but it seems to stuff everything else up.
Anyone know why this might be occurring?
Any help HUGELY appreciated, and thanks in advance!
Gem
XML Parsing Error: not well-formednear3 X day Stag hunt.