10 Replies Latest reply on May 16, 2008 2:21 AM by Lekser

    xml reading in flex

      hello friends ,
      i am new to flex.I need to read a xml file for flex .my code is here


      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;

      private function startService():void
      private function productServiceResultHandler(event:ResultEvent):void

      <mx:HTTPService id="productService" url="data/list1.xml"

      and i got this error...

      SecurityDomain 'file:///E:/workspace/MVID/bin-debug/MVID.html' tried to access incompatible context 'file:///E:/workspace/MVID/bin-debug/MVID.swf'
      [SWF] E:\workspace\MVID\bin-debug\MVID.swf - 786,873 bytes after decompression
      *** Security Sandbox Violation ***
      Connection to data/list1.xml halted - not permitted from file:///E:/workspace/MVID/bin-debug/MVID.swf
      [RPC Fault faultString="Error #2148: SWF file file:///E:/workspace/MVID/bin-debug/MVID.swf cannot access local resource data/list1.xml. Only local-with-filesystem and trusted local SWF files may access local resources." faultCode="InvokeFailed" faultDetail="null"]
      at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::invoke()[E:\dev\3.0.x\frameworks\projects\rpc\ src\mx\rpc\AbstractInvoker.as:263
      at mx.rpc.http.mxml::HTTPService/ http://www.adobe.com/2006/flex/mx/internal::invoke()[E:\dev\3.0.x\frameworks\projects\rpc\ src\mx\rpc\http\mxml\HTTPService.as:234
      at mx.rpc.http::HTTPService/send()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\http\HTTP Service.as:758]

      i think it's the problem of crossdomain policy.But i don't know how to set it...
      pls help me in this...
        • 1. Re: xml reading in flex
          FlexPrashant Level 1
          whenever we use xml file in httpservice we use that event.result.parentnode.subnode
          Like i am using a xml
          <product >
          <label>abcc </abc>
          </product >
          <product >
          <label>abcc </abc>
          </product >

          then to read this xml
          I have to write event.result.mylog.product
          • 2. Re: xml reading in flex
            Hi ,

            Take one xml object.
            Use this sample code.

            billresultXML = new XML(event.result);
            arrBillData=new ArrayCollection();
            var electricCount:Number=Number(billresultXML.GetBill.children().length()+1);
            for (var itemId:Number=1;itemId < electricCount ; itemId++)
            arrBillData.addItem({beginDate:billresultXML.GetBill.GetBillStatus[itemId-1].attribute("s tartdate").toString(),endDate:billresultXML.GetBill.GetBillStatus[itemId-1].attribute("end date").toString(), USE:billresultXML.GetBill.GetBillStatus[itemId-1].attribute("usage").toString(), TOTALCOST:billresultXML.GetBill.GetBillStatus[itemId-1].attribute("totalcost").toString() , DEMAND:billresultXML.GetBill.GetBillStatus[itemId-1].attribute("demand").toString(), billID:billresultXML.GetBill.GetBillStatus[itemId-1].attribute("billId").toString()});
            • 3. xml reading in flex
              LoGicMaNia Level 1
              hi frnds,
              i didn't get solutuion yet..
              Actually i want to read a xml and to add to a tree component..
              i hav attached my code... but it displays nothing and no errors

              can you please help me in it...

              • 4. Re: xml reading in flex
                kcell Level 2
                Hi cvnbgcbn,

                did you used the debugger?
                Is the function "productServiceResultHandler" called ?
                Do you see the correct xml structure in companyData ?
                Can you post a example of the xml which is returned by the httpservice ( event.result) ?
                Is the function "treeLabel" called ?

                best regards,
                • 5. Re: xml reading in flex
                  LoGicMaNia Level 1
                  hi kcell,

                  I am using debugger ...
                  the function "productServiceResultHandler" is calling..
                  When i trace event.result i got [object,object]
                  i also adding the xml i am using...
                  I think the problem is the ,i can't convert the event.result to XML object....
                  it may b the problem

                  pls help me

                  • 6. xml reading in flex

                    i have problem this load XML data.

                    while (d1 <= d2) {
                    var xmlFileName:String=path+dateToString(d1)+".xml";
                    if (d1<d2){
                    var xmlDataService:HTTPService = new HTTPService();
                    xmlDataService.url = xmlFileName;
                    }else {
                    var o:Object=new Object();
                    var createXMLTempService:HTTPService=new HTTPService();

                    this code get 3 parametrs: d1-date(start time period), d2-date(today), path(path to XML files).

                    When load XML files i write result in DataGrid, all result write good. Every row in DataGrid have Date.
                    XML files names: 20.05.2008.xml , 21.05.2008.xml , 22.05.2008.xml , ..... (Example).

                    Problem: some row this Date=20.05, but he stay later when row this Date=21.05. (Example)

                    Question: why happend this?

                    P.S. Please sorry for my very bad english.
                    • 7. Re: xml reading in flex
                      kcell Level 2
                      Hi cvnbgcbn,

                      tried your example, you have to set the resultformat to xml, cause you are casting the event.result to a xml ...
                      <mx:HTTPService id="productService" url="data/list1.xml" resultFormat="xml"

                      best regards
                      • 8. Re: xml reading in flex
                        kcell Level 2
                        Hi Lekser,

                        I would like to suggest that you post your "new" topic to a new forum entry cause otherwise problems will be mixed.
                        ( it may also help if you break your problem down to a small example app which you can post, so others might be able to reproduce your problem)

                        From my point of view your problem looks different cause your using e4x as resultformat.

                        best regards,

                        (may send me a link to you new post and I will try to give a look)
                        • 9. Re: xml reading in flex
                          LoGicMaNia Level 1
                          hi friends,

                          I got the answer....I forget to set resultformat... :)

                          here is the change.... and it's working....Thank you for your comments.