开发者

A better way updating a nested XML

I have a few lines of code:

 lev = arrInfo[1]
 xml = sxml;
 switch(lev){
 case 0: xml = sxml;
 break;
 case 1: var xl:XML = arrInfo[0];
 xml.sublevels = xl;
 break;
 case 2: xl = arrInfo[0];
 xml.sublevels.sublevel.sublevels = xl;
 break;
 case 3: xl = arrInfo[0];                                                                             
 xml.sublevels.sublevel.sublevels.sublevel.sublevels = xl;
 break;
}

In the switch statement, it checks what level of sublevels the xl XML should be attached to and based on the level, it goes to attach it. So, if level three, that means the xl should substitute the sublevels in that level. In case 3: the xl substitutes the sublevels in the sublevel node of the (level-1) sublevels node and if I have case 4: then the xl should replace the sublevels of the sublevel node of the (4-1)开发者_JS百科 sublevels. That would look something like this:

 case 4: xl = arrInfo[0];                                                                             
 xml.sublevels.sublevel.sublevels.sublevel.sublevels.sublevel.sublevels = xl;

However, that means I have to do this manually if I know the number of sublevels in the nested XML, but this will be so much of work if the levels were 20 or someone adds a new level that was not manually checked in the switch statement.

Anyone knows how I can solve this problem?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜