1 Reply Latest reply on Dec 14, 2006 7:04 AM by JeffreyGong

    Help Required on Reading an External XML file in flex

    sanjivsutar
      Hi Experts

      I want some help regarding flex.

      I want to read an external xml file in flex and want to show different datas in different components

      So bacically i need what is the procedure to call an external xml file and the procedure to catch the value of the xml tags and the option (options means ex: "id" or "type inside" "row" tag ) in side the xml file.

      -------------------------------------------
      Here is My xml file named "skn_organ.xml"
      -------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <slide>
      <r>7</r>
      <c>8</c>
      <row id="A01" type="g">
      <organ>Skn</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A02" type="g">
      <organ>Brt</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A03" type="g">
      <organ>Spl</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A04" type="g">
      <organ>Lnode</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A05" type="g">
      <organ>Ske</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A06" type="g">
      <organ>Lun</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A07" type="g">
      <organ>Sgl</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="A08" type="g">
      <organ>Liv</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B01" type="g">
      <organ>Gal</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B02" type="g">
      <organ>Pan</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B03" type="g">
      <organ>Ton</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B04" type="g">
      <organ>Eso</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B05" type="g">
      <organ>Sto</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B06" type="g">
      <organ>Sto</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B07" type="g">
      <organ>Sbl</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="B08" type="g">
      <organ>Col</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C01" type="g">
      <organ>Skn</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C02" type="g">
      <organ>Brt</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C03" type="g">
      <organ>Spl</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C04" type="g">
      <organ>Lnode</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C05" type="g">
      <organ>Ske</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C06" type="g">
      <organ>Lun</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C07" type="g">
      <organ>Sgl</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="C08" type="g">
      <organ>Liv</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="D01" type="g">
      <organ>Gal</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="D02" type="g">
      <organ>Pan</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      <row id="D03" type="g">
      <organ>Ton</organ>
      <link> http://www.designgarbage.com</link>
      </row>
      </slide>
      -----------------------------------------------------------------------

        • 1. Re: Help Required on Reading an External XML file in flex
          JeffreyGong
          Hi sanjivsutar,

          Put your xml file under folder "assets", the application demo is as following

          ====================================================================
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="init()">
          <mx:Script>
          <![CDATA[
          private var mainXML:XML;
          private var loader:URLLoader;

          private function init():void {
          loader = new URLLoader();
          loader.addEventListener(Event.COMPLETE, onComplete);
          loader.load(new URLRequest('assets/skn_organ.xml'));
          }

          private function onComplete(evt:Event):void {
          mainXML = new XML(loader.data)
          out.text += "xml loaded, using E4X syntax: \n\n";
          out.text += "Row 1: "+mainXML.row[0]+"\n"
          out.text += "Row 6: organ = "+mainXML.row[5].organ+"\n"
          out.text += "Row(id='D02'): link = "+mainXML.row.(@id=="D02").link+"\n"
          }
          ]]>
          </mx:Script>
          <mx:TextArea id="out" width="400" height="300"/>
          </mx:Application>
          ======================================================================

          Jeffrey