Front-end:
The Code is as follows:
<! 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>
<Title> js loads xml files and sends them to the server </title>
<Script type = "text/javascript"> <! --
Var xmlHttp = null;
Function f (){
Var xmlDoc = new ActiveXObject ("Msxml2.DOMDocument. 3.0 ");
XmlDoc. async = false;
XmlDoc. load ("xmlfile. xml"); // only changed here. It turns out to be loadXML ("");
SendXml (xmlDoc, 'default. aspx ');
}
// Send the Xml document to the server
Function sendXml (xmlDoc, serverURL ){
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP. 3.0 ");
Var strDoc;
If (typeof (xmlDoc) = "object") // The judgment here is required. You still need to add an xml suffix here.
StrDoc = xmlDoc. xml;
Else
StrDoc = xmlDoc;
XmlHttp. open ("POST", "Default. aspx", true );
XmlHttp. onreadystatechange = getData;
XmlHttp. send (strDoc );
}
Function getData (){
If (xmlHttp. readyState = 4)
{
Var strxml = xmlHttp. responseText;
// Here, we accept Xml documents sent from the server and convert them into xml documents.
Var xmlDoc = new ActiveXObject ("Msxml2.DOMDocument. 3.0 ");
XmlDoc. async = false;
XmlDoc. loadXML (strxml );
// Alert (xmlDoc. xml );
Var singleNode = xmlDoc. selectSingleNode ("/root/person [gender = 'male']"); // The value must be enclosed in quotation marks.
Alert (singleNode. text );
}
}
// --> </Script>
</Head>
<Body>
<Input type = "button" onclick = "f ();" value = "request"/>
</Body>
</Html>
<! 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>
<Title> js loads xml files and sends them to the server </title>
<Script type = "text/javascript"> <! --
Var xmlHttp = null;
Function f (){
Var xmlDoc = new ActiveXObject ("Msxml2.DOMDocument. 3.0 ");
XmlDoc. async = false;
XmlDoc. load ("xmlfile. xml"); // only changed here. It turns out to be loadXML ("");
SendXml (xmlDoc, 'default. aspx ');
}
// Send the Xml document to the server
Function sendXml (xmlDoc, serverURL ){
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP. 3.0 ");
Var strDoc;
If (typeof (xmlDoc) = "object") // The judgment here is required. You still need to add an xml suffix here.
StrDoc = xmlDoc. xml;
Else
StrDoc = xmlDoc;
XmlHttp. open ("POST", "Default. aspx", true );
XmlHttp. onreadystatechange = getData;
XmlHttp. send (strDoc );
}
Function getData (){
If (xmlHttp. readyState = 4)
{
Var strxml = xmlHttp. responseText;
// Here, we accept Xml documents sent from the server and convert them into xml documents.
Var xmlDoc = new ActiveXObject ("Msxml2.DOMDocument. 3.0 ");
XmlDoc. async = false;
XmlDoc. loadXML (strxml );
// Alert (xmlDoc. xml );
Var singleNode = xmlDoc. selectSingleNode ("/root/person [gender = 'male']"); // The value must be enclosed in quotation marks.
Alert (singleNode. text );
}
}
// --> </Script>
</Head>
<Body>
<Input type = "button" onclick = "f ();" value = "request"/>
</Body>
</Html>
Ajax
The Code is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Xml;
Public partial class testXml_Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument ();
Xmldoc. Load (Request. InputStream); // receives xml from the client
Xmldoc. Save (Server. MapPath ("~ "+"/Hello. xml "));
Response. Write (xmldoc. InnerXml); // return the modified Xml document.
Response. End ();
}
}
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Xml;
Public partial class testXml_Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument ();
Xmldoc. Load (Request. InputStream); // receives xml from the client
Xmldoc. Save (Server. MapPath ("~ "+"/Hello. xml "));
Response. Write (xmldoc. InnerXml); // return the modified Xml document.
Response. End ();
}
}
Xml document:
The Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Root>
<Person id = "1">
<Name> tree </name>
<Gender> male </gender>
</Person>
</Root>