Steps:
1. Quote jquery
2, if it is IE, instance activexobject;firefox, example Domparser.
3, processing
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "Xmldom._default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Js/jquery-1.4.2.js" ></script>
<script type= "Text/javascript" >
Get the XML Dom
function Loadxml (xmlstring) {
var xmldoc;
Firefox and other
if (!window. ActiveXObject) {
var parser = new Domparser ();
xmldoc = parser.parsefromstring (xmlstring, "text/xml");
} else {
Ie
xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
Xmldoc.async = "false";
Xmldoc.loadxml (xmlstring);
}
return xmldoc;
}
function Usecllentxmldom () {
try {
var string = "<log><content value=" tests XML DOM usage '/></log> ';
Load
var xmlstring = Loadxml (string);
var xmlcontent = $ (xmlstring). Find ("Content");
if (xmlcontent!= null) {
$ (xmlstring). Find ("Content"). each (function () {
var Contentvalue = $ (this). attr ("value");
Show the resulting data
$ ("#DomValue"). HTML (contentvalue);
});
}
}
catch (e) {
Throw e;
}
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<a style= "Cursor:pointer" onclick= "Usecllentxmldom ()" > Calling client xmldom</a>
<br/>
Display data:
<div id= "Domvalue" >
</div>
</div>
</form>
</body>
In Firefox, I found that the XML string directly to the Jquery,jquery can also be processed directly, but not in IE. such as the bottom code.
Copy Code code as follows:
<script type= "Text/javascript" >
//Only available under Firefox
function use Cllentxmldom () {
try {
var string = ' <log><content value= ' tests XML DOM usage '/></log> ';
//Fetch XML string
XMLString = $ (string);
var xmlcontent = $ (xmlstring). Find ("Content");
if (xmlcontent!= null) {
$ (xmlstring). Find (' Content '). each (function () {
var contentvalue = $ (this). attr (" Value ");
//Displays the resulting data
$ ("#DomValue"). HTML (contentvalue);
});
}
}
catch (e) {
throw E;
}
}
</script>