Flex, use URL for Data Binding

Source: Internet
Author: User

There are some issues to consider when loading XML using namespaces and URL parameters. In this simple example you will use to add parameters to the loading URL and display the date in a list.

Usually you get your XML by calling a URL with parameters like this one:

'Http: // niimo.com/api? Type = xml & method = Public'

If you use this URL with Flex httpservice you get a syntax error:

<Mx: httpservice id = "latestusers" url = "http://niimo.com/api? Type = xml & method = Public "/>

Error (in this case ):

'This reference to entity "method" must end with the ";" delimiter .'

Adding the <mx: Request> tag you can add parameters to your url and flex doesn't complain.

<Mx: httpservice id = "latestusers" url = "http://niimo.com/api">
<Mx: Request>
<Method> Public </method>
<Type> XML </type>
</MX: Request>
</MX: httpservice>

This example shows how to load XML using a URL with parameters and XML Namespaces with E4X.

Code:


<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "vertical" creationcomplete = "Init ();">

<Mx: httpservice id = "latestusers" url = "http://niimo.com/api" showbusycursor = "true" resultformat = "E4X" result = "onresult (event);">
<Mx: Request>
<Method> Public </method>
<Type> XML </type>
</MX: Request>
</MX: httpservice>

<Mx: SCRIPT>
Public var niimousers: xmllist;

Namespace users = "http://niimo.com/api/personal ";

Private function Init (): void {
Latestusers. Send ();
}

Private function onresult (Event: resultevent): void {
VaR resultxml: xml = event. result as XML;
 
VaR userlist: xmllist = resultxml. niimo. niimorecord;

Use namespace users;
Niimousers = userlist. Nickname;
}

]>
</MX: SCRIPT>

<Mx: Label text = "niimo users:"/>
<Mx: List dataprovider = "{niimousers}" width = "150" Height = "500"/>
</MX: Application>

The above code loads the public timeline of the latest posts from niimo and puts the usernames of the posters in a list.

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.