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

As3 xml node change/replace/delete

Explorer ,
Oct 24, 2012 Oct 24, 2012

Hi,

Im working with piece of code that creates dynamically xml and send it to DB.

var _round:XML;

_round = new XML(<round/>);

_round.@num = currentRound;

var answer:XML = <answer/>;

answer.@num = 0;

trial.appendChild(_round);

In some cases I appendChild like that:

     xml.level.appendChild(_round);

this is in a situation when _round xml is not in a xml.level already

but what if I would like to delete that exisiting round node and put another new one in that place? what Should i do? I tried:

delete xml.level.round; //then append new _round

or

for each (var round:XML in xml.level) {

      round.replace(round.childIndex(), _round);

}

None of this works. Few other wierd errors appears when I have tried to delete that node or replace it.

What is a best way to do it? thanks

TOPICS
ActionScript
4.1K
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 , Oct 24, 2012 Oct 24, 2012

i edited my message to try and make sense out of your message.  check it.

Translate
Community Expert ,
Oct 24, 2012 Oct 24, 2012

what's trial?  what xmlLevel?

do you mean you have something like:

var xmlLevel:XML;

xmlLevel = new XML(<level/>);

var answer0:XML = <answer/>;

answer0.@num = 0;

var currentRound:int = 1;

var _round1:XML;

_round1 = new XML(<round/>);

_round1.@num = currentRound;

_round1.appendChild(answer0);

currentRound = 2;

var answer1:XML = <answer/>;

answer1.@num = 1;

var _round2:XML;

_round2 = new XML(<round/>);

_round2.@num = currentRound;

_round2.appendChild(answer1);

xmlLevel.appendChild(_round1);

xmlLevel.appendChild(_round2);

and there's an update to currentRound=2:

currentRound = 2;

var answer2:XML = <answer/>;

answer2.@num = 22;

and you want to update xmlLevel round 2 with the most recent answer?  if yes, use:

xmlLevel.round.(@num==2).replace("answer",answer2);

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 ,
Oct 24, 2012 Oct 24, 2012

I din't want to copy a long code there, so my mistake.

Basically I appended few other xml elements to round like for example, answer, trial and few others. So round it's complex dynamic 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
Community Expert ,
Oct 24, 2012 Oct 24, 2012

i edited my message to try and make sense out of your message.  check it.

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 ,
Oct 25, 2012 Oct 25, 2012

Yes. Someting like that.

I used your : xmlLevel.round.(@num==2).replace("answer",answer2);

and I found a bug somewhere else. Anyway, it's fixed now. Thanks

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
Community Expert ,
Oct 25, 2012 Oct 25, 2012
LATEST

you're welcome.

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