How to replace invalid characters in XML using Javascript or PhP

Posted by Raind on Stack Overflow See other posts from Stack Overflow or by Raind
Published on 2010-06-16T12:38:33Z Indexed on 2010/06/16 12:42 UTC
Read the original article Hit count: 173

Filed under:

Hi,

Need help here for the following:

Running PhP, javascript, MySQL, XML.

1) Retrieving file from MySQL and stored it onto XML file.
2) Use javascript function to load XML file (that stored those data).
3) It produces invalid characters in XML file.

STEP 1 : Sample of the code in PhP -> Loading MySQL DB to store data onto XML file $file= fopen("MapDeals2.xml", "w"); $_xml ="\n"; $_xml .="\n";

while($row1_ThisWeek = mysql_fetch_array($result1_ThisWeek)) { $rRName = $row1_ThisWeek['Retailer_Name']; $rRAddress = $row1_ThisWeek['Retailer_Address1']; $rRAddressPostCode = $row1_ThisWeek['Retailer_AddressPostCode1'];

}

     $_xml .= "<DEAL>\n"; 
     $_xml .= "<DealDescription>" . $d_Description . "</DealDescription>\n";
     $_xml .= "<DealURL>" . $d_URL . "</DealURL>\n";
     $_xml .= "<DealRName>" . $rRName . "</DealRName>\n";
     $_xml .= "<DealRAddress>" . $rRAddress . "</DealRAddress>\n";
     $_xml .= "<DealRPostCode>" . $rRAddressPostCode . "</DealRPostCode>\n";
     $_xml .=  "</DEAL>\n";

    } 

} $_xml .="\n"; fwrite($file, $_xml); fclose($file);

STEP 2 : Sample of the code in Javscript -> Loading XML file

xhttp.open("GET","Test2.xml", false); xhttp.send(""); xmlDoc=xhttp.responseXML;

var x=xmlDoc.getElementsByTagName("Employee");

parser = new DOMParser(); xmlDoc = parser.parseFromString("MapDeals2.xml", "text/xml");

for (i=0;i"; . . .

}

Is there a solution for the above? Looking forward to hear from you soon.

Cheers

© Stack Overflow or respective owner

Related posts about Xml