Home >Web Front-end >JS Tutorial >js cross-browser implementation of converting strings into xml objects_javascript skills

js cross-browser implementation of converting strings into xml objects_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:21:271113browse

Pay attention to the problem of multiple versions of IE

Copy code The code is as follows:

function loadXML(xmlString ) {
var xmlDoc = null;
if (!window.DOMParser && window.ActiveXObject) {
var xmlDomVersions = ['MSXML.2.DOMDocument.6.0', 'MSXML.2.DOMDocument.3.0 ', 'Microsoft.XMLDOM'];
for (var i = 0; i < xmlDomVersions.length; i ) {
try {
xmlDoc = new ActiveXObject(xmlDomVersions[i]);
xmlDoc.async = false;
xmlDoc.loadXML(xmlString);
break;
} catch (e) {
}
}
}
else if (window .DOMParser && document.implementation && document.implementation.createDocument) {
try {

domParser = new DOMParser();
xmlDoc = domParser.parseFromString(xmlString, 'text/xml');
} catch (e) {
}
}
else {
return null;
}

return xmlDoc;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn