But it is an XML string, it will be different in the two browsers. in IE, you can directly use the loadxml method to parse the XML string, and in FF, you need to use the parsefromstring () of the domparser object () the method is
VaR oparser = new domparser ();
Xmldoc = oparser. parsefromstring (xmlstr, "text/XML ");
In order to be useful in both browsers, I think of the exception handling method of javascrui, that is, try... catch...
CopyCode The Code is as follows: function toxml (strxml ){
Try {
Xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. loadxml (strxml );
}
Catch (e ){
VaR oparser = new domparser ();
Xmldoc = oparser. parsefromstring (strxml, "text/XML ");
}
Return xmldoc;
}
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]
Check that 1400 is displayed in both IE and FF !!Copy codeThe Code is as follows: function formattoxml (strxml ){
VaR isie = function (){
VaR Ie =/MSIE/I. Test (navigator. useragent );
Return ie;
}
VaR exc = function (){
VaR xmldoc = NULL;
If (isie ())
{
Xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. loadxml (strxml );
} Else {
// Firefox2.0 and safari2.0
Xmldoc = (New domparser (). parsefromstring (strxml, "text/XML ");
}
Return xmldoc;
}
Return exc ();
}
functions are the same. They are used to parse XML strings in IE and ff. However, some people say that XML strings must be , If XML version = "1.0" encoding = "gb2312"?>, The parsing results are inconsistent, so the above example does not contain these characters.