1. xpath4as
Xpath4as2 is an as2 extension class provided by xfactorstudio and supports thth1.0.
Go to iis8 \ zh_cn \ First Run \ Classes and restart flash.
Xfactorstudio also provides an XmlDataSet class to improve processing efficiency.
Download: http://www.xfactorstudio.com/Actionscript/AS2/XmlDataSet/XmlDataSet.zip
2. as in flash:
The sendAndLoad method of flash is very interesting. It sends xml data as a form request. For example, the xml snippet sent below:
<Login methodName = \ "login \" username = \ "Admin \" password = \ "111111 \"/>
The request is the same as the following:
Request. Form. allKeys [0] = "login methodName ";
Request. Form [0]. toString = \ "login \" username = \ "Administrator \" password = \ "111111 \";
That is, a key-Value Pair named login methodName is submitted in form.
XPathAxes. stringValue is a static method used to obtain all the text values of the specified node type array.
XPath. selectNodes is also a static method with two parameters. Parameter 1 specifies the content of the xpath query (xmlNode), and parameter 2 is an xpth query string, this method returns a node array that meets the specified conditions.
Import com. xfactorstudio. xml. xpath .*;
Var targetURL: String = "http: // localhost/xxir/WebForm. aspx ";
XML. prototype. ignoreWhite = true;
Var AXML: XML = new XML ();
AXML. onLoad = AXMLOnLoad;
Function AXMLOnLoad (success: Boolean ){
If (success ){
Var nd = XPathAxes. stringValue (XPath. selectNodes (this, "/adminOP/UserName") [0]);
Trace (nd );
} Else {
Trace ("connectionFailed ");
}
}
This. login_btn.onPress = function (){
Var QXML: XML = new XML ();
// Create data in XML format to be sent to the server
Var QEmn: XMLNode = QXML. createElement ("QParam ");
QEmn. attributes. methodName = "login ";
QEmn. attributes. username = "Admin ";
QEmn. attributes. password = "11111 ";
QXML. appendChild (QEmn );
// Send XML data to the server
QXML. sendAndLoad (targetURL, AXML );
}
The above code is common, and the request sent is as follows:
<QParam password = "11111" username = "Admin" methodName = "login"/>
The returned value is as follows:
<? Xml version = "1.0"?>
<AdminOP xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
<ID>
1
</ID>
<AdminName>
Admin
</AdminName>
<UserName>
Admin
</UserName>
<Password>
111111
</Password>
<Purview>
1
</Purview>
<LastLoginIP>
127.0.0.1
</LastLoginIP>
<LastLoginTime>
2005-10-10T07: 22: 22.0000000 + 08: 00
</LastLoginTime>
<LastLogoutTime>
2005-10-10T08: 22: 00.0000000 + 08: 00
</LastLogoutTime>
<LoginTimes>
2
</LoginTimes>
<RndPassword>
11111 ddff
</RndPassword>
<EnableMultiLogin>
False
</EnableMultiLogin>
<AdminPurview_Article>
0
</AdminPurview_Article>
<AdminPurview_Soft>
0
</AdminPurview_Soft>
<AdminPurview_Photo>
0
</AdminPurview_Photo>
<AdminPurview_Shop>
0
</AdminPurview_Shop>
<AdminPurview_Others>
0-0-0
</AdminPurview_Others>
<ArrClass_View>
0-0-0
</ArrClass_View>
<ArrClass_Input>
0-0-0
</ArrClass_Input>
<ArrClass_Check>
0-0-0
</ArrClass_Check>
<ArrClass_Manage>
0-0-0
</ArrClass_Manage>
</AdminOP>
3. asp.net processes requests and replies
First, the request is processed and a value of the XmlNode type is returned, as follows:
Private XmlNode getRequestXML (){
Int vals = Request. TotalBytes;
Byte [] bytes = Request. BinaryRead (vals );
String strContent = System. Text. Encoding. UTF8.GetString (bytes );
XmlDocument doc = new XmlDocument ();
Doc. LoadXml (strContent );
Return doc. FirstChild;
}
Then process the sending back based on the request. Here a serialized class adminOP is used and XmlDocument is returned. The Code is as follows:
Private XmlDocument adminlogin (XmlNode xnd ){
AdminOP OP = new adminOP (xnd. Attributes ["username"]. Value );
XmlSerializer ops = new XmlSerializer (typeof (adminOP ));
System. IO. MemoryStream bs = new MemoryStream (100 );
Ops. Serialize (bs, OP );
Bs. Position = 0;
XmlDocument doc = new XmlDocument (bs );
Doc. Load (xtr );
Return doc;
}
Write the instance of the serialized adminOP class to Response:
Response. Write (adminlogin (getRequestXML (). OuterXml );
This. Response. Flush ();
Finally, add the contentType = "text/xml" indicator to @ Page.
The aspx. cs code is as follows:
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using System. Xml;
Using System. Xml. Serialization;
Using System. IO;
Namespace akscnClaw
{
Public class WebForm: System. Web. UI. Page
{
Private void Page_Load (object sender, System. EventArgs e)
{
Response. Write (adminlogin (getRequestXML (). OuterXml );
This. Response. Flush ();
}
Override protected void OnInit (EventArgs e)
{
InitializeComponent ();
Base. OnInit (e );
}
Private void InitializeComponent ()
{
This. Load + = new System. EventHandler (this. Page_Load );
}
// GET requests in XML format
Private XmlNode getRequestXML (){
Int vals = Request. TotalBytes;
Byte [] bytes = Request. BinaryRead (vals );
String strContent = System. Text. Encoding. UTF8.GetString (bytes );
XmlDocument doc = new XmlDocument ();
Doc. LoadXml (strContent );
Return doc. FirstChild;
}
// Serialized output result
Private XmlDocument adminlogin (XmlNode xnd ){
AdminOP OP = new adminOP (xnd. Attributes ["username"]. Value );
XmlSerializer ops = new XmlSerializer (typeof (adminOP ));
System. IO. MemoryStream bs = new MemoryStream (100 );
Ops. Serialize (bs, OP );
Bs. Position = 0;
XmlDocument doc = new XmlDocument (bs );
Doc. Load (xtr );
Return doc;
}
}
}