Function loadxml (flag, XML ){
VaR xmldoc;
// For IE browsers
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 {
// Create an XML Object
Xmldoc = new activexobject (aversions [I]);
Break;
} Catch (oerror ){
}
}
If (xmldoc! = NULL ){
// Load XML data in synchronous Mode
Xmldoc. async = false;
// Load according to the XML document name
If (flag = true ){
Xmldoc. Load (XML );
} Else {
// Load according to the string that represents the XML document
Xmldoc. loadxml (XML );
}
// Return the root element node of the XML document.
Return xmldoc.doc umentelement;
}
} Else {
// For non-ie browsers
If (document. Implementation & document. Implementation. createdocument ){
/*
The first parameter indicates the URL of the namespace used by the XML document.
The second parameter indicates the name of the root node of the XML document to be created.
The third parameter is a doctype object, which indicates the definition of doctype in the XML document to be created. Generally, null is used directly.
Here we need to load an existing XML document, so first create an empty document, so use the following method
*/
Xmldoc = Document. Implementation. createdocument ("", "", null );
If (xmldoc! = NULL ){
// Load according to the XML document name
If (flag = true ){
// Load XML data in synchronous Mode
Xmldoc. async = false;
Xmldoc. Load (XML );
} Else {
// Load according to the string that represents the XML document
VaR oparser = new domparser ();
Xmldoc = oparser. parsefromstring (XML, "text/XML ");
}
// Return the root element node of the XML document.
Return xmldoc.doc umentelement;
}
}
}
Return NULL;
}