使用IE时,可以执行以下操作-
alert("XML Root IE: " + xmlDoc.documentElement.tagName); // ok
alert("Xml: " + xmlDoc.documentElement.xml); // ok但是对于FireFox,函数xml、innerxml、outerxml都是未定义的。
alert("tagName: " + xmlDoc.documentElement.tagName); // ok
alert("Xml Content: " + xmlDoc.documentElement.xml); // undefined
alert("Xml innerxml: " + xmlDoc.documentElement.innerxml); // undefined
alert("Xml outerxml: " + xmlDoc.documentElement.outerxml); // undefined如何在FireFox上获得实际的XML?(我知道我正确地读取了XML,因为"documentElement.tagName“在IE和FF上都是正确的)
谢谢,
阿塔拉
编辑:相关FF代码如下:
var xmlDoc;
function fLoadXml() {
// alert("fLoadXml()");
if (window.ActiveXObject) { // IE
fLoadXmlIE()
} else if (document.implementation && document.implementation.createDocument) { // FF
fLoadXmlFF()
}
}
function fLoadXmlFF() {
// alert("fLoadXmlFF()");
xmlDoc = document.implementation.createDocument("","",null) ;
xmlDoc.async = false;
xmlDoc.onload = fReadXmlFF;
var loaded = xmlDoc.load("myFile.xml");
alert("loaded: " + loaded);
}
function fReadXmlFF() {
alert("fReadXmlFF()");
alert("tagName: " + xmlDoc.documentElement.tagName);
alert("Xml Content: " + xmlDoc.documentElement.xml); // undefined
alert("Xml innerxml: " + xmlDoc.documentElement.innerxml); // undefined
alert("Xml outerxml: " + xmlDoc.documentElement.outerxml); // undefined
}发布于 2012-03-19 19:14:14
在- http://www.hiteshagrawal.com/javascript/convert-xml-document-to-string-in-javascript中找到的
解决方案:
function fReadXmlFF() {
alert("tagName: " + xmlDoc.documentElement.tagName); // ok
strXml = (new XMLSerializer()).serializeToString(xmlDoc); // ok
. . . 发布于 2012-03-19 01:14:32
xml只是一个IE属性,可以尝试其他的属性,比如ChildNodes和NodeValue,在这里检查一下:http://www.w3schools.com/dom/dom_document.asp
https://stackoverflow.com/questions/9760320
复制相似问题