解決方法如下:
復制代碼 代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>xml轉化成字符串</title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
//使fireFox也支持xmlDom.xml
if (!document.all) {
Node.prototype.__defineGetter__(
"xml",
function () {
return (new XMLSerializer).serializeToString(this);
});
}
alert(1);
var xmlStr = "<test>Hello world</test>";
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlStr, "text/xml");
alert(xmlDoc.documentElement.nodeName);
alert(xmlDoc.xml);
});
</script>
</head>
<body>
</body>
</html>