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.