jamesflowers
-
Posts
3 -
Joined
-
Last visited
Posts posted by jamesflowers
-
-
this is creating the XML data from a DB before hand , I dont have cust.xml already .
Thanks
-
I have the code below , and when I run it on my website , it returns a XML Parsing Error: not well-formed error , which says it has a problem reading the & i think
please see http://www.jamesflowersreports.com/php/xml2.php
I think it has something to wiht the str_replace as when I change the $row['customerName'] . "</Name>\n"; to $row['customerNumber'] . "</Name>\n"; as a test it works fine , I understand XML cant handle special characters , how would prevent this happening?
code as below
$query = "SELECT * FROM customers";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<Name>" . $row['customerName'] . "</Name>\n";
// Escaping illegal characters
$row['text'] = str_replace("&", "&", $row['text']);
$row['text'] = str_replace("<", "<", $row['text']);
$row['text'] = str_replace(">", ">", $row['text']);
$row['text'] = str_replace("\"", """, $row['text']);
$xml_output.= "\t\t<Number>" . $row['customerNumber'] . "</Number>\n";
$xml_output.= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;regards
James
creating a XML file from MYSQL with PHP
in PHP Coding Help
Posted
cool , thanks
I have noticed it doesnt catch eacute's are these not recognised by CDATA ?
thanks