As3 xml node change/replace/delete

Explorer ,
Oct 24, 2012

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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

TOPICS
ActionScript

Views

3.6K

Likes

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

As3 xml node change/replace/delete

Explorer ,
Oct 24, 2012

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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

TOPICS
ActionScript

Views

3.6K

Likes

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
Oct 24, 2012 0
Adobe Community Professional ,
Oct 24, 2012

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 24, 2012 1
Explorer ,
Oct 24, 2012

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Oct 24, 2012 0
Adobe Community Professional ,
Oct 24, 2012

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 24, 2012 0
Explorer ,
Oct 25, 2012

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 25, 2012 0
kglad LATEST
Adobe Community Professional ,
Oct 25, 2012

Copy link to clipboard

Copied

you're welcome.

Likes

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
Reply
Loading...
Oct 25, 2012 0