//把string转成xml对象
function loadXML(flag, xml) {
var xmlDoc;
if (window.ActiveXObject) {
var aVersions = ["MSXML2.DOMDocument.6.0", "MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0", "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument", "Microsoft.XmlDom"];
for (var i = 0; i < aVersions.length; i++) {
try {
xmlDoc = new ActiveXObject(aVersions[i]);
break;
} catch (oError) {
}
}
if (xmlDoc != null) {
xmlDoc.async = false;
if (flag == true) {
xmlDoc.load(xml);
} else {
xmlDoc.loadXML(xml);
}
return xmlDoc.documentElement;
}
} else {
if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
if (xmlDoc != null) {
if (flag == true) {
xmlDoc.async = false;
xmlDoc.load(xml);
} else {
var oParser = new DOMParser();
xmlDoc = oParser.parseFromString(xml, "text/xml");
}
return xmlDoc.documentElement;
}
}
}
return null;
}
//下面这个例子是打开一个页面上传文件,返回的是一个xml,类似
$("#" + attachBtnClientID).click(function () {
var a = window.showModalDialog("../FileUpload.aspx", window, "center=1, resize=1");
if (a == null || a == "undefined") {
return;
}
var xml = loadXML(false, a);
if (xml == null) {
return;
}
var index = uploadCount++;
var idNode = loadXML(false, "
xml.appendChild(idNode);
uploadFileXml.appendChild(xml);
var path = xml.selectNodes("SavedFilename")[0].text;
var filename = xml.selectNodes("Filename")[0].text;
var filetype = xml.selectNodes("Type")[0].text;
var html = "
姓名 | 年龄 | 班级 |
---|---|---|