0 Replies Latest reply on Nov 3, 2010 8:55 AM by SiHoop

    Importing xml

    SiHoop Level 1

      What is the correct way to import xml from a data file. I don't have a problem when the data is stored internally, but things go wrong when I put the same data into a text file. How should I import the data so it ends up in an xml object so I can begin to extract data from it?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
          <mx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.http.HTTPService;
                  private var httpService:HTTPService
                  private var databaseDataXML:XML=new XML;
                  private function init():void{
                      var params:Object = new Object();
                      httpService = new HTTPService();
                      httpService.url = "data.xml";
                      httpService.method = "GET";
                      httpService.addEventListener("result", extractData);
                      httpService.send(params)
                      var demo:XML =
                          <scores>           
                              <score>               
                                  <value>4</value>               
                              </score>
                              <score>               
                                  <value>7</value>               
                              </score>
                              <score>               
                                  <value>8</value>               
                              </score>
                          </scores>
                          trace("Length 1="+demo.score.length())
                  }
                  private function extractData(event:ResultEvent):void{
                      databaseDataXML= XML(event.result.score);
                      trace("Length 2="+databaseDataXML.length())
                  }
              ]]>
          </mx:Script>
      </mx:Application>