0
需要幫助以下內容:如何使用Javascript或PhP替換XML中的無效字符
運行PhP,javascript,MySQL,XML。
1)從MySQL中檢索文件並將其存儲到XML文件中。
2)使用javascript函數加載XML文件(存儲這些數據)。
3)它在XML文件中產生無效字符。
步驟1:在PHP代碼的樣本 - >裝載MySQL數據庫到數據存儲到XML文件
$file= fopen("MapDeals2.xml", "w");
$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$_xml .="<MAP>\n";
while($row1_ThisWeek = mysql_fetch_array($result1_ThisWeek)) {
$rRName = $row1_ThisWeek['Retailer_Name'];
$rRAddress = $row1_ThisWeek['Retailer_Address1'];
$rRAddressPostCode = $row1_ThisWeek['Retailer_AddressPostCode1'];
//} commented out from the original
$_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";
}
//} commented out from the original
$_xml .="</MAP>\n";
fwrite($file, $_xml);
fclose($file);
。步驟2:在Javscript代碼的樣本 - >裝載XML文件
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<x.length;i++)
{
// alert ('Generating FOR loop');
var d1 = x[i].getElementsByTagName("EmployeeDescription")[0].childNodes[0].nodeValue;
var e1 = "<br></br>";
.
.
.
}
有沒有解決上述問題的方法?希望能早日得到你的回覆。
乾杯
你的代碼亂七八糟。在試圖清理它的時候,它還有兩個比開啓支架更近的支撐杆。我評論他們。如果此修改與您的代碼不符,請編輯您的問題。 – Artefacto 2010-06-16 12:51:31