Steps:
1. Reference Jquery
2. for IE, the instance ActiveXObject; Firefox, And the instance DOMParser.
3. Processing
Copy codeThe Code is 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">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<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, etc.
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 = 'test Xml Dom use'/> </Log> ";
// Load
Var xmlString = LoadXML (string );
Var xmlContent = $ (xmlString). find ("Content ");
If (xmlContent! = Null ){
$ (XmlString). find ("Content"). each (function (){
Var ContentValue = $ (this). attr ("value ");
// Display the obtained data
$ ("# DomValue" pai.html (ContentValue );
});
}
}
Catch (e ){
Throw e;
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<A style = "cursor: pointer" onclick = "UseCllentXmlDom ()"> call the client XmlDom </a>
<Br/>
Show data:
<Div id = "DomValue">
</Div>
</Div>
</Form>
</Body>
</Html>
In FireFox, I found that Jquery can directly process XML strings directly to Jquery, but not IE. The following code is used.Copy codeThe Code is as follows: <script type = "text/javascript">
// Applicable only in firefox
Function UseCllentXmlDom (){
Try {
Var string = "<Log> <Content value = 'test Xml Dom use'/> </Log> ";
// Retrieve the XML string
XmlString = $ (string );
Var xmlContent = $ (xmlString). find ("Content ");
If (xmlContent! = Null ){
$ (XmlString). find ("Content"). each (function (){
Var ContentValue = $ (this). attr ("value ");
// Display the obtained data
$ ("# DomValue" pai.html (ContentValue );
});
}
}
Catch (e ){
Throw e;
}
}
</Script>