httpService and XMLListCollection

孤街浪徒 提交于 2019-12-12 03:48:44

问题


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


回答1:


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...



来源:https://stackoverflow.com/questions/14115940/httpservice-and-xmllistcollection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!