hi guys,
I am trying to make a xml structure like the following in flash itself.
<index>
<chapter1>
<topic1>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic1>
<topic2>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic2>
<topic3>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic3>
</chapter1>
<chapter2>
<topic1>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic1>
<topic2>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic2>
<topic3>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic3>
</chapter2>
<chapter3>
<topic1>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic1>
<topic2>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic2>
<topic3>
<content1>this is content1</content1>
<content2>this is content2</content2>
</topic3>
</chapter3>
</index>
To create this structure in flash itself, i have create a XML object and used [COLOR=Red]appendChild[/COLOR],
[COLOR=Red]createElement [/COLOR]methods. The code is below.
var xml:XML = new XML();
var node:XMLNode = xml.createElement("index");
var chapter1:XMLNode = xml.createElement("chapter1");
var chapter2:XMLNode = xml.createElement("chapter2");
var chapter3:XMLNode = xml.createElement("chapter3");
var topic1:XMLNode = xml.createElement("topic1");
var topic2:XMLNode = xml.createElement("topic2");
var topic3:XMLNode = xml.createElement("topic3");
var content1:XMLNode = xml.createElement("content1");
var content2:XMLNode = xml.createElement("content2");
var txtNodes1:XMLNode = xml.createElement("this is content1");
var txtNodes2:XMLNode = xml.createElement("this is content2");
var chapters:Array = [chapter1, chapter2, chapter3];
var topics:Array = [topic1, topic2, topic3];
var contents:Array = [content1, content2];
var txtNodes:Array = [txtNodes1, txtNodes2];
for (var i:Number = 0; i<chapters.length; i++) {
var chapter:XMLNode = chapters*;
for (var j:Number = 0; j<topics.length; j++) {
var topic:XMLNode = topics[j];
for (var k:Number = 0; k<contents.length; k++) {
var content:XMLNode = contents[k];
content.appendChild(txtNodes[k]);
topic.appendChild(contents[k]);
}
chapter.appendChild(topic);
}
node.appendChild(chapter);
}
xml.appendChild(node);
trace(xml);
Strangely after creating the structure, i have found [COLOR=Red]topics,content[/COLOR] been added not to all chapters but the last chapter. I don’t know why? It should show [COLOR=Red]topics, contents[/COLOR] in every chapter as per the loop, but its not.
i think its got some problem with [COLOR=Red]xml.appendChild [/COLOR]method.
any ideas?
thanks
satish kumar