httpService和XMLListCollection [英] httpService and XMLListCollection

查看:164
本文介绍了httpService和XMLListCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目出现了一个问题,我尝试用我的xml数据填充一个列表,这些数据是从一个php文件中获取的。我用httpservice调用php文件,这个文件返回xml数据。现在看来有一个问题,但我没有得到任何错误。我只是知道调试后,我的XMLListCollection仍然为空。



这是我的代码:

 <?xml version =1.0encoding =utf-8?> 
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mx
xmlns:components =components。*
creationComplete =httpService.send() >

< s:layout>
horizo​​ntalAlign =center/>
< / s:layout>
< fx:Script>
<![CDATA [
import mx.rpc.events.ResultEvent;
导入mx.collections.ArrayCollection;
导入mx.collections.XMLListCollection;

导入mx.rpc.events.FaultEvent;
导入mx.controls.Alert;
private var alert:Alert;
$ b private function httpService_fault(evt:FaultEvent):void {
var title:String = evt.type +(+ evt.fault.faultCode +);
var text:String = evt.fault.faultString;
alert = Alert.show(text,title);
Bezoekers.removeAll();


private function httpService_result(evt:ResultEvent):void {
var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker;
Bezoekers = new XMLListCollection(xmlList);

}






]]>
< / fx:Script>
< fx:声明>
< s:HTTPService id =httpService
url =http://localhost/projectnieuw/src/data/bezoekersList.php
resultFormat =e4x
故障= httpService_fault(事件);
result =httpService_result(event)/>
<! - < fx:Model id =lijstAlleLedensource =httpAlleLeden/> - >
<! - < s:ArrayCollection id =acBezoekerssource ={Bezoekers}/> - >
< s:XMLListCollection id =Bezoekers/>
< / fx:声明>





<组件:标题/>
< s:HGroup gap =50>

< components:BezoekersList bezoekerList ={Bezoekers}/>
< components:ReservationForm />

< / s:HGroup>

< / s:Application>

我似乎并没有得到什么错。



预先致谢

来自比利时的问候

解决方案

你的XMLListCollection保持为null 表示 Bezoekers = new XMLListCollection(xmlList); 给它null。所以首先尝试跟踪那个结果不是从服务器端的空。要测试服务器端的响应,你有一个窍门是,在Web浏览器中打开你的HTTPService的URL,并在Web浏览器中获取XML数据。如果获得成功,则尝试 resultFormat =xml而不是 resultFormat =e4x并读取 HTTPService结果文件类型,以了解如何使用它。它也有一些针对XML的案件到案例的解决方案。



这可以帮助你...


I have a problem with my project where I try to fill a list with my xml data that I get out of an php file. I call the php file with a httpservice and this file returns xml data. Now it seems that there is a problem, but I don't get any error. I just know after debugging that my XMLListCollection remains null.

Here is my code :

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
                 xmlns:components="components.*"
                 creationComplete="httpService.send()">

    <s:layout>
        <s:VerticalLayout paddingTop="20" gap="20" 
                          horizontalAlign="center" />
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection; 
            import mx.collections.XMLListCollection; 

            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;
            private var alert:Alert;

            private function httpService_fault(evt:FaultEvent):void {
                var title:String = evt.type + " (" + evt.fault.faultCode + ")";
                var text:String = evt.fault.faultString;
                alert = Alert.show(text, title);
                Bezoekers.removeAll();
            }

            private function httpService_result(evt:ResultEvent):void {
                var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker;
                Bezoekers = new XMLListCollection(xmlList);

            }






        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:HTTPService id="httpService"
                       url="http://localhost/projectnieuw/src/data/bezoekersList.php"
                       resultFormat="e4x"
                       fault="httpService_fault(event);"
                       result="httpService_result(event)" />
        <!--<fx:Model id="lijstAlleLeden" source="httpAlleLeden" />-->
        <!--<s:ArrayCollection id="acBezoekers" source="{Bezoekers}"/>-->
        <s:XMLListCollection id="Bezoekers"/>
    </fx:Declarations>





    <components:Heading/>
    <s:HGroup gap="50">

        <components:BezoekersList bezoekerList="{Bezoekers}" />
        <components:ReservationForm/>

    </s:HGroup>

</s:Application>

I don't seem to get what's wrong.

Thanks in advance

Greetings from Belgium

解决方案

your XMLListCollection remains null means Bezoekers = new XMLListCollection(xmlList); gives to it null. so first of all try to trace that result was not null from server-side. To test server-side response, you have one trick is that, open your HTTPService's URL in web-browser and get XML data in Web-browser. if get success then try resultFormat="xml" instead of resultFormat="e4x" and read documentation of HTTPService's result Type to know how to use it. it has also some case-to-case basis solution for XML.

May this will help you...

这篇关于httpService和XMLListCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆