Flex: Two Methods for httpservice to process XML files: the XML generation method by ASP, and the use of flex to define variables and assign values ....

Source: Internet
Author: User
Tags name database

// *********************** Define the URL and parameters as variables and dynamically pass the value...

<? XML version = "1.0" encoding = "UTF-8" ?>
< MX: Application Xmlns: MX = "Http://www.macromedia.com/2003/mxml"  
Initialize = "Myhttpdata. Send (); trace ('calling Service ');" >
< MX: script >
<! [CDATA [
VaR myurl: String = "http://www.bpurcell.org/blog/rss.cfm ";
VAR mode: String = "short ";
VaR mode2: String = "cat ";
VaR catid = "14 ";
]>
</ MX: script >
<! -- If you set resultformat to object it turns the Returning data into an object -->
< MX: httpservice URL = "{Myurl }" ID = "Myhttpdata" Method = "Get" Resultformat = "Object" >
< MX: Request >
< Mode > {Mode} </ Mode >
< Mode2 > {Mode2} </ Mode2 >
< Catid > {Catid} </ Catid >
</ MX: Request >  
</ MX: httpservice >
< MX: textarea Text = "{Myhttpdata. Result. RDF. Channel. Title }" Width = "250"   />
< MX: textarea Text = "{Myhttpdata. Result. RDF. item [0]. Description }"  
Width = "250" Height = "200"   />
< MX: textarea Text = "{Myhttpdata. Result }" Width = "250" Height = "500"   />
</ MX: Application >

 

Method 2: Use xmllist to output complete XML data. The output data attribute is XML. <? XML version = "1.0" encoding = "UTF-8" ?>
< S: Application Xmlns: FX = "Http://ns.adobe.com/mxml/2009"
Xmlns: S = "Library: // ns.adobe.com/flex/spark"  
Xmlns: MX = "Library: // ns.adobe.com/flex/halo"
Width = "1024" Height = "768" Backgroundcolor = "#020202" Creationcomplete = "Menus. Send ()" >
< FX: script >
<! [CDATA [
Import MX. Collections. arraycollection;
Import MX. rpc. Events. resultevent;

[Bindable]
Private var roomsxml: XML;

[Bindable]
Private var menuinfo: xmllist;
Protected function httpserviceappsresulthandler (Event: resultevent): void
{
Roomsxml = New XML (event. Result );
Menuinfo = roomsxml. node;
Trace (menuinfo );
//// The output data is:
<Node name = "living room space" url = "space1.xml"/>
<Node name = "kitchen space" url = "space1.xml"/>
<Node name = "bedroom space" url = "space1.xml"/>
<Node name = "restaurant space" url = "space1.xml"/>
<Node name = "bathroom space" url = "space1.xml"/>
<Node name = "children's room" url = "space1.xml"/>
<Node name = "other space" url = "space1.xml"/>
Trace (menuinfo [0]. @ name );
//// The output data is: Living room space
}
]>
</ FX: script >
< FX: Declarations >
< MX: httpservice ID = "Menus" Resultformat = "XML" URL = "Dataasset/rooms. xml" Result = "Httpserviceappsresulthandler (event )" /> /// Important: You must set resultformat = "XML" to output the XML data type"
</ FX: Declarations >
</ S: Application > Httpservice processes XML files Connasp. mxml

Code : <? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.aDobe.com/2006/mxml "layout =" absolute "creationcomplete =" productsrequest. Send () ">
<Mx: httpservice id = "productsrequest" url = "http: // localHost/flexasp_ 1.asp"/>
<Mx: DataGrid x = "20" Y = "80" id = "productgrid" width = "400" dataprovider = "{productsrequest. lastresult. guestbook. Guests}">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name"/>
<Mx: datagridcolumn headertext = "message" datafield = "message"/>
</MX: columns>
</MX: DataGrid>
</MX: Application>
XML generation using ASP Flexasp_1.asp <%
Response. contenttype = "text/XML"
Response. charset = "UTF-8"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. provider = "Microsoft. Jet. oledb.4.0 ;"
Conn. Open Server. mappath ("./flash_asp/database. mdb ")
SQL = "Select name, message from Guestbook"
Set rs = conn. Execute (SQL)
Rs. movefirst ()
Response. Write ("<? XML version = '1. 0' encoding = 'utf-8'?> ")
Response. Write ("<guestbook> ")
While (not Rs. EOF)
Response. Write ("<guest> ")
Response. Write ("<Name>" & RS ("name") & "</Name> ")
Response. Write ("<message>" & RS ("message") & "</message> ")
Response. Write ("</guest> ")
Rs. movenext ()
Wend
Rs. Close ()
Conn. Close ()
Response. Write ("</guestbook> ")
%>

Access Database
Database Name database. MDB
Table Name: Guestbook
Field: ID, name, message

The XML file is normally displayed separately, and the DataGrid In Flex does not display data. Why answer:Dataprovider = "{productsrequest. lastresult. guestbook. Guest }"

 

 

Related Article

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.