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.