Skip navigation
Currently Being Moderated

how delete nodes according to his attribute ?

Dec 20, 2009 8:54 AM

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);
   
   
}
 
Replies
  • Rob Day
    2,296 posts
    Oct 16, 2007
    Currently Being Moderated
    Dec 20, 2009 10:43 AM   in reply to cosmicvibs

    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[i].@id==String(who_Id)) {

              delete xml.page.adverts[i];

         }

    }

     

    trace(xml);

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points