0 Replies Latest reply on Aug 16, 2012 8:39 AM by wasted bombat

    Parsing xml file

    wasted bombat

      Hello

      I would like to parse xml file in code. Here is my xml:

       

          <?xml version="1.0" encoding="UTF-8"?>

          <people>

             <person>

                 <name>James</name>

                 <age>24</age>

             </person>

             <person>

                 <name>Cynthia</name>

                 <age>33</age>

             </person>

          </people>

       

      And 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:my_file="services.my_file.*"

                         applicationDPI="160">

              <fx:Script>

                  <![CDATA[

                      import mx.events.FlexEvent;

                      protected function label2_creationCompleteHandler(event:FlexEvent):void

                      {

                          getDataResult.token = my_file.getData();

                          //here Iam getting an error  "A term is undefined and has no properties."

                          label2.text = getDataResult.lastResult[1].name;   

                      }

                 

                  ]]>

                 

              </fx:Script>

              <fx:Declarations>

                  <s:CallResponder id="getDataResult"/>

                  <my_file:My_file id="my_file"/>

                  <!-- Place non-visual elements (e.g., services, value objects) here -->

              </fx:Declarations>

              <s:Label id="label2" x="140" y="142" creationComplete="label2_creationCompleteHandler(event)"

                       text="{getDataResult.lastResult[0].name}"/>

          </s:Application>

       

      I would like to parse an element of my xml and then assign it to my label. But I am getting an error "A term is undefined and has no properties." I am not really sure if this is a good way to parse a xml file. I have seen some tutorials about xml parsing in builder but none really solves my problem. Can anybody help me Iam new and I want to try to make some app based on xml.