Flex practice-read XML files

Source: Internet
Author: User
Tags file url glassfish

There are several ways to read XML files in flex, mainly using httpservice and webserivice
This afternoon, I tried to use httpservice + server and only use httpservice to read the content of the XML file.
Select tomcat or glassfish V2 for the server

I tried the glassfish V2 server, but as long as the URL is correctly imported, the server type should not be a problem
Next we will introduce this practice:

1) directly read the local XML file without using the server
Create an XML file states. XML in the current directory.

<? XML version = "1.0" encoding = "UTF-8"?>
<Result>
<Nodea> meteorwj </nodea>
<NodeB> eleven </NodeB>
</Result>

Create a flex application project: xmltest. mxml

<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX ="
Http://www.adobe.com/2006/mxml"
Creationcomplete = "xmlrecord. Send ()" layout = "absolute">
<Mx: httpservice showbusycursor = "true" url = "states. xml" id = "xmlrecord"/>
<Mx: DataGrid width = "712" Height = "338" dataprovider = "{xmlrecord. lastresult. Result}">
<Mx: columns>
<Mx: datagridcolumn headertext = "sectiona" datafield = "nodea" width = "200"/>
<Mx: datagridcolumn headertext = "sectionb" datafield = "NodeB" width = "200"/>
</MX: columns>
</MX: DataGrid>
</MX: Application>


Note:
Creationcomplete = "xmlrecord. Send ()", you must add this sentence to complete the initialization data loading.
Dataprovider = "{xmlrecord. lastresult. Result}", the content of dataprovider must be specific to the node you want to display

Run the program:



2) run on the server

Special steps:
Put the XML file in the server directory and change the URL above to the File URL under the server
For example:
<Mx: httpservice showbusycursor = "true" url ="Http: // localhost: 8080/flexxmltest/xmlfile/states. xml"
Id = "xmlrecord"/>

Start the server before running the main program

The other steps are the same as the previous method, and the running result is the same as the previous method.

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.