6 Replies Latest reply on Dec 11, 2011 3:34 PM by drkstr_1

    Write XML Files

    HenriqueCanova

      HI

       

      I'm tying to edit one xml file to put more information or change some information

       

      my xml code like this one:

       

      [code]

       

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

      <home>

                <controller>

                          <ip>192.168.0.100</ip>

                          <port>2345</port>

                </controller>

                <general>

                          <devicenumber></devicenumber>

                </general>

                <devices>

                </devices>

                <channels>

                </channels>

                <types>

                </types>

                <zones>

                </zones>

                <cenes>

                </cenes>

      </home>

       

      [/code]

       

       

      I'm trying to insert one new device on <devices> node like this

       

      [code]

       

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

      <home>

        <controller>

             <ip>192.168.0.100</ip>

             <port>2345</port>

        </controller>

        <general>

             <devicenumber></devicenumber>

        </general>

        <devices>

           <device>

                     <index>1</index>

                    <add>0013a2004064f4a8</add>

                   <channelnumber>8</channelnumber>

                   <usedchannel>0</usedchannel>

                  <description>test</description>

            </device>

        </devices>

        <channels>

        </channels>

        <types>

        </types>

        <zones>

        </zones>

        <cenes>

        </cenes>

      </home>

       

      [/code]

       

      I used this to load the xml:

       

       

       

      [code]

       

      import flash.net.URLLoader;

      public  var req:URLRequest;

      public var loader:URLLoader;

       

      private function initxml():void{

       

      loader = new URLLoader();

      loader.addEventListener( Event.COMPLETE, foiLido );

      loader.load( new URLRequest( "template.xml" ) );

       

      }

       

       

       

      public var xml:XML;

      private function foiLido(evt:Event):void

      {

      XML.ignoreWhitespace =true;

      xml = new XML(evt.target.data);

       

      }

       

       

      [/code]

       

       

      I tried to use xml.insertchild an does not work

       

      anyone now how can i do it?

       

      and if is possible how can i delete one node like <device></device>

       

      thanks a lot

       

      Henrique