/** 解析XML字符串
* @param str 要解析的XML字符串
* @return document对象
*/
function loadXml(str) {
if (str == null)
return null;
var doc = new ActiveXObject("MSXML.DOMDocument");
doc.async = false;
doc.loadXML(str);
var oErr = doc.parseError;
if (oErr.errorCode != 0) {
if (str.length > 5 && str.substring(0,5) == "<!DOC") {
return null;
}else{
alert("解析XML数据错误:\n" + oErr.reason + "\nLine:" + oErr.line + "\nLinepos:" + oErr.linepos + "\nsrcText:\n" + oErr.srcText);
}
return null;
}
return doc;
}
/** 解析XML文件
* @param file 要解析的XML文件
* @return document对象
*/
function loadFile(file) {
var doc = new ActiveXObject("MSXML.DOMDocument");
doc.async = false;
doc.load(file);
var oErr = doc.parseError;
if (oErr.errorCode != 0) {
alert("解析XML文件[" + file + "]错误:\n" + oErr.reason + "\nLine:" + oErr.line + "\nLinepos:" + oErr.linepos + "\nsrcText:\n" + oErr.srcText);
return null;
}
return doc;
}
首先了解这两个方法(解析XML);
var oDoc = loadXml("<ROOT>....</ROOT>");加载从后台返回的数据。
* @param str 要解析的XML字符串
* @return document对象
*/
function loadXml(str) {
if (str == null)
return null;
var doc = new ActiveXObject("MSXML.DOMDocument");
doc.async = false;
doc.loadXML(str);
var oErr = doc.parseError;
if (oErr.errorCode != 0) {
if (str.length > 5 && str.substring(0,5) == "<!DOC") {
return null;
}else{
alert("解析XML数据错误:\n" + oErr.reason + "\nLine:" + oErr.line + "\nLinepos:" + oErr.linepos + "\nsrcText:\n" + oErr.srcText);
}
return null;
}
return doc;
}
/** 解析XML文件
* @param file 要解析的XML文件
* @return document对象
*/
function loadFile(file) {
var doc = new ActiveXObject("MSXML.DOMDocument");
doc.async = false;
doc.load(file);
var oErr = doc.parseError;
if (oErr.errorCode != 0) {
alert("解析XML文件[" + file + "]错误:\n" + oErr.reason + "\nLine:" + oErr.line + "\nLinepos:" + oErr.linepos + "\nsrcText:\n" + oErr.srcText);
return null;
}
return doc;
}
首先了解这两个方法(解析XML);
var oDoc = loadXml("<ROOT>....</ROOT>");加载从后台返回的数据。