i have a error when running this code .. i run fine when there is no special characteres in database. if its has special characters then i got the error please solve me i am very thankful.
Following Error are occured when any special charachers in database like " ' & ? " i don't why those error come .. and i am not using DOM or XMLWrite just simple create the xml via file, and clerify 1 thing that CDDATA also not working for my code i check it. Please tell me some thing how could i make the xml with error less..
following are the code:
$file= fopen("../xml/{$productID}.xml" , "w");
$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$_XML = "<!DOCTYPE Server SYSTEM \"opt/pdos/etc/pdoslrd.dtd\">";
$_xml .="<productsnode>";
while ($row = mysql_fetch_array($productQuery, MYSQL_ASSOC)) {
$_xml .=" <product>";
$_xml .=" <productID>" . $row['productID'] . "</productID>";
$_xml .=" <productName>" . htmlspecialchars($row['productName']) . "</productName>";
$_xml .=" <productDescription>" . htmlspecialchars($row['productDescription']) . "</productDescription>";
$_xml .=" <productPicture>" . htmlspecialchars($row['productPic']) . "</productPicture>";
$_xml .=" <category>";
$_xml .=" <categoryID>" . $row['categoryID'] . "</categoryID>";
$_xml .=" <categoryName>" . htmlspecialchars($row['categoryName']) . "</categoryName>";
$_xml .=" <categoryDescription>" . htmlspecialchars($row['categoryDiscription']) . "</categoryDescription>";
$_xml .=" <categoryPicture>" . htmlspecialchars($row['categoryPic']) . "</categoryPicture>";
$_xml .=" <subCategory>";
$_xml .=" <subCategoryID>" . $row['subCategoryID'] . "</subCategoryID>";
$_xml .=" <subCategoryName>" . htmlspecialchars($row['subCategoryName']) . "</subCategoryName>";
$_xml .=" <subCategoryDetail>" . htmlspecialchars($row['subCategoryDescription']) . "</subCategoryDetail>";
$_xml .=" </subCategory>";
$_xml .=" </category>";
$_xml .=" </product>";
}
$_xml .="</productsnode>";
fwrite($file, $_xml);
fclose($file);
SET NAMES 'utf8'?htmlspecialcharswhen working with XML (!= HTML).