Communication between flash and. Net (2): Application of XML objects

Source: Internet
Author: User
Communication between flash and. Net (2): Application of XML objects

Introduction:
This test mainly uses the XML Object of actionscr ī Pt. The flash client sends XML (<sendinfo> <value> ABC </value> </sendinfo>) to the server (Asp.. Net), the server converts the <value> character value to uppercase and sends it back to the Flash client in XML format (<replayinfo value = 'value'/>.

Key knowledge points:
For details, see the Flash MX Professional 2004 help document.
1. xml. sendandload (URL, targetxmlobject
Encode the specified XML object as an XML document and send it to the specified URL using the POST method. Download the server response and load it to the targetxmlobject specified in the parameter. The server response is loaded in the same way as the load () method.
2. xml. onload ()
Flash Player calls the XML file from the server. If the XML document is successfully received, the success parameter is true. If this document is not received, or an error occurs when receiving responses from the server, the success parameter is false.
CodeAnd description:
Actionscr platinum PT:
Stop ();
VaR strxml = "<sendinfo> <value> ABC </value> </sendinfo> ";
VaR sendxml: xml = New XML (); // defines the XML Object sent to the server
Sendxml. ignorewhite = true; // when true, the white space is ignored.
Sendxml. parsexml (strxml); // interpret the XML string as an object
VaR rexml: xml = New XML (); // defines the XML Object of the information returned by the receiving server.
Rexml. ignorewhite = true;
Rexml. onload = getreplayinfo; // defines the call to the "getreplayinfo" function when the load and sendandload Methods load data.
Sendxml. sendandload ("your url", rexml );
Trace ("server processing ...");
Function getreplayinfo ()
{
VaR getxml: xml = New XML ();
Getxml. ignorewhite = true;
Getxml. parsexml (this );
If (getxml. firstchild. nodename = "replayinfo ")
{
Trace (getxml. firstchild. Attributes. value );
}
Else
{
Trace ("server error! ");
}
} ASP. NET Protected void page_load (Object sender, eventargs E)
{
Stream xmlstream = request. inputstream;
Dataset DS = new dataset ();
DS. readxml (xmlstream );
Xmldocument xmldoc = new xmldocument ();
Xmldoc. loadxml (Ds. getxml ());
String value = xmldoc. selectsinglenode ("sendinfo"). childnodes [0]. innertext; // value of node <value>
Value = value. toupper (); // converts the value to uppercase.
Response. Write ("<replayinfo value = '" + value + "'/> ");
// Send back to the client flash
}
Note: The following information (marked in red) should be added to the HTML page declaration of ASP. NET to ensure that the page correctly receives XML data streams.
<% @ Page Language = "C #" Validaterequest = "false" Autoeventwireup = "true" codefile = "xmltest. aspx. cs" inherits = "xml_xmltest" %> Test results: Processing the server...
ABC

posting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.