Yes in that case you would, and before deleting the level 2 append level3 to
level 2's parent.



Kind of (not at all tested) like this..



for each (var item:XML in myxml..level2) {
    item.parent.append(item..level3);

    delete item;

}



you may actually need 2 loops one for the delete. If the above technique
doesn’t work try the copy()



item.parent.append(item..level3.copy());



sorry no time to actually test anything here.



jason




  -----Message d'origine-----
  De : [email protected] [mailto:[EMAIL PROTECTED] la
part de phipzkillah
  Envoyé : mercredi 10 janvier 2007 21:58
  À : [email protected]
  Objet : [flexcoders] Re: XML manipulation


  That makes sense and I guess I should have rephrased my question. I
  have multiple levels of level1 and I need to preserve the hierarchy.
  I would assume you would need a for loop to do this. Any ideas?

  <level1>
  <level2>

  <level3/>
  <level3/>
  <level3/>

  </level2>
  </level1>

  <level1>
  <level2>

  <level3/>
  <level3/>

  </level2>
  </level1>

  Transformed to...

  <level1>

  <level3/>
  <level3/>
  <level3/>

  </level1>

  <level1>

  <level3/>
  <level3/>

  </level1>
  --- In [email protected], "Jason Hawryluk" <[EMAIL PROTECTED]> wrote:
  >
  > Yes; basically
  >
  > Grab level3 into an xmllist var
  >
  > delete level 2 append level 3 to level 1.
  >
  > var tempxml:XMLList = myxml..level3;
  > delete myxml.level2;
  > myxml.append(tempxml);
  >
  > the above code is off the top of my head. May and may not work :)
  >
  > jason
  >
  >
  > -----Message d'origine-----
  > De : [email protected] [mailto:[EMAIL PROTECTED] la
  > part de phipzkillah
  > Envoyé : mercredi 10 janvier 2007 21:28
  > À : [email protected]
  > Objet : [flexcoders] Re: XML manipulation
  >
  >
  > Ben,
  >
  > Thanks for your help. It works great!
  >
  > I have another question that I'm not sure if you will be able to
  > answer or not. If I have 3 levels of hierarchy in my XML and I want
  > to remove level 2 (but not its children - level 3) how would you go
  > about doing that? Eliminate level 2 while promoting level 3.
  >
  > <level1>
  > <level2>
  >
  > <level3/>
  > <level3/>
  > <level3/>
  >
  > </level2>
  > </level1>
  >
  > Transformed to...
  >
  > <level1>
  >
  > <level3/>
  > <level3/>
  > <level3/>
  >
  > </level1>
  >
  > --- In [email protected], "ben.clinkinbeard"
  > <ben.clinkinbeard@> wrote:
  > >
  > > Wow, I had no idea deleting a set of nodes would be this hard.
  > > Apparently this is how its done:
  > >
  > > for each(var node:XML in myXML..remove)
  > > {
  > > delete(myXML..remove[node.childIndex()]);
  > > }
  > >
  > > HTH,
  > > Ben
  > >
  > >
  > > --- In [email protected], "phipzkillah" <pkrasko@> wrote:
  > > >
  > > > How can I remove a selection of children from an xml tree.
  > > >
  > > > var myXML:XML =
  > > > <root>
  > > > <cluster>
  > > > <remove>
  > > > <garbage/>
  > > > <garbage/>
  > > > <garbage>
  > > > <garbage1/>
  > > > <garbage2/>
  > > > <garbage3/>
  > > > </garbage>
  > > > </remove>
  > > > <remove>
  > > > <garbage>
  > > > <garbage1/>
  > > > <garbage2/>
  > > > </garbage>
  > > > <garbage/>
  > > > </remove>
  > > >
  > > > <keep>
  > > > <info/>
  > > > <info/>
  > > > <info>
  > > > <goodStuff/>
  > > > <goodStuff/>
  > > > <goodStuff>
  > > > <good1/>
  > > > <good2/>
  > > > </goodStuff>
  > > > </info>
  > > > </keep>
  > > > </cluster>
  > > > </root>
  > > >
  > > > ......................
  > > >
  > > > Now I want to keep all the good stuff.
  > > >
  > > > I want the final xml tree to look like this:
  > > > <root>
  > > > <cluster>
  > > > <keep>
  > > > <info/>
  > > > <info/>
  > > > <info>
  > > > <goodStuff/>
  > > > <goodStuff/>
  > > > <goodStuff>
  > > > <good1/>
  > > > <good2/>
  > > > </goodStuff>
  > > > </info>
  > > > </keep>
  > > > </cluster>
  > > > </root>
  > > >
  > > > I tried doing this with no luck:
  > > >
  > > > myXML = delete myXML..remove;
  > > >
  > > > Any ideas why that doesn't work?
  > > >
  > >
  >



  

Reply via email to