Flex loads external XML

Source: Internet
Author: User

Method 1: load XML

<Mx: XML id = "xmlf" Source = "student. xml"/>

<Mx: panel X = "0" Y = "200" Title = "XML class loading XML">
<Mx: DataGrid dataprovider = "{xmlf. Student}">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name"/>
<Mx: datagridcolumn headertext = "Age" datafield = "Age"/>
<Mx: datagridcolumn headertext = "gender" datafield = "sex"/>
</MX: columns>
</MX: DataGrid>
</MX: Panel>

Method 2: load XML using the model class

Set <mx: XML id = "xmlf" Source = "student. xml"/>

Replace it with <mx: Model id = "xmlf" Source = "student. xml"/>.

Method 3: Use urlloader

<Mx: SCRIPT>
<! [CDATA [
[Bindable]
Private var Loader: urlloader = new urlloader ();
[Bindable]
Private var XML: xml = New XML ();

Private function Init (): void {
Loader. Load (New URLRequest ("student. xml "));
Loader. addeventlistener (event. Complete, oncomplete );
}
Private function oncomplete (EVT: Event): void {
Xml = XML (loader. data );
}
]>
</MX: SCRIPT>
<Mx: DataGrid x = "100" Y = "200" dataprovider = "{XML. Children ()}">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name"/>
<Mx: datagridcolumn headertext = "Age" datafield = "Age"/>
<Mx: datagridcolumn headertext = "gender" datafield = "sex"/>
</MX: columns>
</MX: DataGrid>

Method 4: httpservice class loading

<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" fontsize = "12" layout = "absolute" creationcomplete = "xmldata. Send ()">
<Mx: httpservice id = "xmldata" url = "student. xml" result = "resulthandle (event)"/>

<Mx: SCRIPT>
<! [CDATA [
Import MX. Collections. arraycollection;
Import MX. rpc. Events. resultevent;
[Bindable]
Private var arrayxml: arraycollection;
[Bindable]
Public var I: Int = 0;

/** Call this function after loading */
Public Function resulthandle (Event: resultevent): void
{
Arrayxml = event. Result. Students. student;
}

]>
</MX: SCRIPT>

<Mx: DataGrid x = "92" Y = "348" width = "390" dataprovider = "{arrayxml}">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name"/>
<Mx: datagridcolumn headertext = "Age" datafield = "Age"/>
<Mx: datagridcolumn headertext = "gender" datafield = "sex"/>
<Mx: datagridcolumn headertext = "Grade" datafield = "linoleic"/>
</MX: columns>
</MX: DataGrid>
</MX: Application>

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.