JS Implemented Cross Browser Resolution of XML File Instances
- 2021-06-29 09:53:03
- OfStack
This article provides an example of how JS implements cross-browser parsing of XML files.Share it for your reference, as follows:
The following code loads an XML document ("note.xml") into the XML parser:
<script type="text/javascript">
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function loadXMLDoc(){
var xmlhttp = GetXmlHttpObject();
xmlhttp.open("GET","note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
return xmlDoc;
}
PS: Regarding xml format files, here are some online tools recommended for you again. I believe you can use them in future programming development:
Online XML formatting/compression tool:
http://tools.ofstack.com/code/xmlformat
xml code online formatting and beautification tool:
http://tools.ofstack.com/code/xmlcodeformat
Online XML/JSON mutual conversion tool:
http://tools.ofstack.com/code/xmljson
More information about JavaScript can be found in this site: JavaScript Operation XML Document Skills Summary, ajax Operation Skills Summary in JavaScript, json Operation Skills Summary in JavaScript, JavaScript Switching Special Effects and Skills Summary, JavaScript Find Algorithms Skills Summary, JavaScript Animation Special Effects and Skills Summary, JavaScript Errors and Debugging Skills Summary, etc.Summary of JavaScript Data Structure and Algorithmic Techniques, Summary of JavaScript Traversal Algorithms and Techniques, and Summary of JavaScript Mathematical Usage
I hope that the description in this paper will be helpful to everyone's JavaScript program design.