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

how delete nodes according to his attribute ?

Explorer ,
Dec 20, 2009 Dec 20, 2009

Sorry i will stop to ask that much in the forum and try myself but  i have another problem.. I would like to be able to delete a node according to his attribute  "id" of the node "adverts". ?????

  here is the xml script :

<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);
   
   
}
TOPICS
ActionScript
578
Translate
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

correct answers 1 Correct answer

Community Expert , Dec 20, 2009 Dec 20, 2009

It could be a simple as:

delete xml.page.adverts[who_Id];

But once a node is deleted the number names would no longer match the node number.

So maybe you are looking for this:

var xml:XML =

<Pages>

<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</a

...
Translate
Community Expert ,
Dec 20, 2009 Dec 20, 2009

It could be a simple as:

delete xml.page.adverts[who_Id];

But once a node is deleted the number names would no longer match the node number.

So maybe you are looking for this:

var xml:XML =

<Pages>

<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>

var who_Id:int=1;

for (var i:Number = 0; i <  xml.page.adverts.length(); i++) {

     if (xml.page.adverts.@id==String(who_Id)) {

          delete xml.page.adverts;

     }

}

trace(xml);

Translate
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
LATEST

thanks a lot . and MERY CHRISMAS

Translate
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