4 Replies Latest reply: Dec 19, 2009 1:57 PM by iFezec RSS

    probleme copying XML: nodes please help

    cosmicvibs Community Member

      hi here is my simple script:

      i dont understand why my templist:XMLList doesnt work:

       

      var Pages:XML=<Pages />;
      Pages.page = <page />;
      Pages.page.@id="5";
      Pages.page.adverts=<adverts />;
      Pages.page.adverts.adfile=<adfile />;
      Pages.page.adverts.adwidth=<adwidth />;
      Pages.page.adverts.adheight=<adheight />;
      Pages.page.adverts.adposx=<adposx />;
      Pages.page.adverts.adposy=<adposy />;

       

      Pages.page.adverts.adfile="yoyo";
      Pages.page.adverts.adwidth="2";
      Pages.page.adverts.adheight="3";
      Pages.page.adverts.adposx="6";
      Pages.page.adverts.adposy="8";

       

      var templist:XMLList= Pages.page.adverts.copy();
      templist[0].adfile="yiyi";
      templist[0].adwidth="56";
      templist[0].adheight="568";
      templist[0].adposx="1078";
      templist[0].adposy="2005";
      Pages.page.adverts.insertChildBefore(Pages.page.adverts, templist);
      trace(Pages);

       

       

      IT TRACE IN THE OUTPUT THIS

      <Pages>
        <page id="5">
          <adverts>
            <adfile>yoyo</adfile>
            <adwidth>2</adwidth>
            <adheight>3</adheight>
            <adposx>6</adposx>
            <adposy>8</adposy>
          </adverts>
        </page>
      </Pages>

       

      INSTEAD OF TRACING THAT :

      <Pages>
        <page id="5">
          <adverts>
            <adfile>yoyo</adfile>
            <adwidth>2</adwidth>
            <adheight>3</adheight>
            <adposx>6</adposx>
            <adposy>8</adposy>
          </adverts>

      <adverts>
             <adfile>yiyi</adfile>
             <adwidth>56</adwidth>
             <adheight>568</adheight>
             <adposx>1018</adposx>
             <adposy>2005</adposy>
           </adverts>
        </page>
      </Pages>