• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

replace value in a xml node

Explorer ,
Dec 19, 2009 Dec 19, 2009

Copy link to clipboard

Copied

hello again: i have an xml like this one, How can i change the values of the nodes   <adposx> and   <adposy> of the node array "YAYA" .I did that :

this.Pages.page.adverts[1].adposx= newvalue;

this.Pages.page.adverts[1].adposY= newvalue;

but it dont work

<Pages>


  <page id="Page2">
    <adverts>
      <adfile>YOYO</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>514</adposx>
      <adposy>200</adposy>
    </adverts>
    <adverts>
      <adfile>YAYA</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>514</adposx>
      <adposy>200</adposy>
    </adverts>
  <adverts>
       <adfile>YUYU</adfile>
       <adwidth>1</adwidth>
       <adheight>50</adheight>
       <adposx>514</adposx>
       <adposy>200</adposy>
     </adverts>

  <adverts>
       <adfile>YIYI</adfile>
       <adwidth>1</adwidth>
       <adheight>50</adheight>
       <adposx>514</adposx>
       <adposy>200</adposy>
     </adverts>

</page>
</Pages>

TOPICS
ActionScript

Views

434

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 19, 2009 Dec 19, 2009

Copy link to clipboard

Copied

as far as i know to do this requires good judgement on xml.

you have to first acquire as an xml object the node you wish to replace.

and then you can replace that node with another node or you can individually adjust 1 line but from a parent node.

var pg=<Pages>
  <page id="Page2">
    <adverts>
      <adfile>YOYO</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>514</adposx>
      <adposy>200</adposy>
    </adverts>
    <adverts>
      <adfile>YAYA</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>514</adposx>
      <adposy>200</adposy>
    </adverts>
  <adverts>
       <adfile>YUYU</adfile>
       <adwidth>1</adwidth>
       <adheight>50</adheight>
       <adposx>514</adposx>
       <adposy>200</adposy>
     </adverts>

  <adverts>
       <adfile>YIYI</adfile>
       <adwidth>1</adwidth>
       <adheight>50</adheight>
       <adposx>514</adposx>
       <adposy>200</adposy>
     </adverts>

</page>
</Pages>

var pg:XML=<Pages>

  <page id="Page2">

    <adverts>

      <adfile>YOYO</adfile>

      <adwidth>1</adwidth>

      <adheight>50</adheight>

      <adposx>514</adposx>

      <adposy>200</adposy>

    </adverts>

    <adverts>

      <adfile>YAYA</adfile>

      <adwidth>1</adwidth>

      <adheight>50</adheight>

      <adposx>514</adposx>

      <adposy>200</adposy>

    </adverts>

  <adverts>

       <adfile>YUYU</adfile>

       <adwidth>1</adwidth>

       <adheight>50</adheight>

       <adposx>514</adposx>

       <adposy>200</adposy>

     </adverts>

  <adverts>

       <adfile>YIYI</adfile>

       <adwidth>1</adwidth>

       <adheight>50</adheight>

       <adposx>514</adposx>

       <adposy>200</adposy>

     </adverts>

</page>

</Pages>

var xml=pg..page.child(0)

//trace(xml)

xml.replace([4],<adposy>newValue'</adposy>)

trace(pg)


basically you have to adjust a node at once or continue to replace

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 20, 2009 Dec 20, 2009

Copy link to clipboard

Copied

LATEST

thanks it wotks... now i have another challenge.  here is the xml script : i would like to be able to delete a node according to the attribut  "id" of the node "adverts". ?????

<page id="Page1">
    <adverts id="0">
      <adfile>file1</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>212</adposx>
      <adposy>375</adposy>
    </adverts>
    <adverts id="1">
      <adfile>file2</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>7</adposx>
      <adposy>69</adposy>
    </adverts>
    <adverts id="2">
      <adfile>file3</adfile>
      <adwidth>1</adwidth>
      <adheight>50</adheight>
      <adposx>83</adposx>
      <adposy>303</adposy>
    </adverts>
  </page>
</Pages>

I tried like this but it didnt work :

function deleteme(evt:MouseEvent):void {
    var who_Id:int=evt.target.parent.parent.id;   // just to get the id number
    var who:String=evt.target.parent.parent.name;
    this.removeChild(evt.target.parent.parent);
    this.evt.target.parent.parent= null;
    delete Pages.page.adverts.(@id==who_Id);  //can change who_Id by a number for test
    trace(Pages);
   
   
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines