PDA

View Full Version : XML Node reading problem... Urgent



NovemberRain
November 18th, 2004, 11:24 PM
This seems so long but i just give the whole things to get an indea.

This is the structure of XML File (genealogy.xml) and call as an external file.

<?xml version="1.0" encoding="iso-8859-1"?>
<genealogy>
<g1>
<Director title = "Son" />
<Seffire title = "Daughter" />
<Jain title = "Sister" />
<Stropper title ="Mother" />
<Pegy title ="Mother" descr = "Flash provides movie clips with defined parameters, called components, to aid in developing rich user experiences in Flash movies." thumb = "thumbs/person1.jpg"/>
<Aimy title ="Daughter" descr1 = "For an interactive introduction to components, choose Help > Tutorials > Introduction to Components" thumbone = "thumbs/person2.jpg"/>
</g1>
<g2>
<Mahin title = "Son" />
<Jeffy title = "Daughter" />
<Reetha title = "Sister" />
<Developer title ="Mother" />
<EzyOhia title ="Mother" descr = "Flash provides movie clips with defined parameters, called components, to aid in developing rich user experiences in Flash movies." thumb = "thumbs/person1.jpg"/>
<Okachi title ="Daughter" descr1 = "For an interactive introduction to components, choose Help > Tutorials > Introduction to Components" thumbone = "thumbs/person2.jpg"/>
</g3>
</genealogy>



Read the first group of people i use the following code


on (press, release) {
_root.dispTree(xmlStr.firstChild.firstChild, 6);
}


The result is "Director to Aimy" get from the function works fine :-)
But i want to add next geneation like <g2></g2> with a group of people in The XML how to read that..
Is it like ?????????


on (press, release) {
_root.dispTree(xmlStr.firstChild.firstChild.firstC hild, 6);
} //How to avoid firstChild.firstChild.firstChild.....and so on
Any suggestion will really appreciable

:diss:

Johnny64
November 19th, 2004, 04:17 AM
on (press, release) {
_root.dispTree(xmlStr.firstChild.childNodes[1], 6);
}

http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/js/html/wwhelp.htm?href=Part_ASLR.html

=)

NovemberRain
November 19th, 2004, 04:29 AM
<g2>
<Mahin title = "Son" />
<Jeffy title = "Daughter" />
<Reetha title = "Sister" />
<Developer title ="Mother" />
<EzyOhia title ="Mother" descr = "Flash provides movie clips with defined parameters, called components, to aid in developing rich user experiences in Flash movies." thumb = "thumbs/person1.jpg"/>
<Okachi title ="Daughter" descr1 = "For an interactive introduction to components, choose Help > Tutorials > Introduction to Components" thumbone = "thumbs/person2.jpg"/>
</g2>

Thanks.. it's working. one more doubt if u don't mind. :D
Imagin this scenario. In the last <g2></g2> Okachi has two children. How can i accommodate them and read those values too .. This the function i've written for the previous issue..I think u can check only the commented portion. The rest of the things a bit confused evenf or me. :puzzled:



_root.xmlArray = new Array();
_root.yPos = 100;
function dispTree(str, loop) {
_root.valArray = loop;
xmlStr = new XML();
xmlStr.ignoreWhite = true;
xmlStr.load("genealogy.xml");

xmlStr.onLoad = function(success) {
if (success) {
rootNode = str;
var siblings = rootNode.childNodes;
for (var i = 0; i<loop; i++) {
currentSibling = siblings[i];
tagName = currentSibling.attributes.title;
if (tagName != null) {
_root.rboard._visible = true;
_root.rboard.attachMovie(tagName, "bname" add i, i);
x = _root.rboard.attachMovie(tagName, "bname" add i, i);
_root.rboard["bname" add i]._x = 0;
_root.rboard["bname" add i]._y = yPos;
_root.rboard["bname" add i].caption = currentSibling.nodeName;//I've taken the node name and dynamically write to the duplicated clips. In the last case i'm not having childelements for the nodeNames I've already make out.
_root.rboard["bname" add i].captionPointer = currentSibling.attributes.title;
yPos += 80;
_root.xmlArray.push(_root.rboard["bname" add i]);
}
}
x.pointer._visible = false;
x.captionPointer = " ";
}
};
_root.yPos = 100;
}

Johnny64
November 19th, 2004, 11:00 AM
I don't know what you mean?

but here i cleared up your code

check to see if it still works :)



function dispTree(rootNode, loop) {
yPos = 100;
var siblings = rootNode.childNodes;
for (var i = 0; i<loop; i++) {
currentSibling = siblings[i];
tagName = currentSibling.attributes.title;
if (tagName != null) {
_root.rboard._visible = true;
tagName_mc = _root.rboard.attachMovie(tagName, "bname"+i, i);
tagName_mc._x = 0;
tagName_mc._y = yPos;
tagName_mc.caption = currentSibling.nodeName;
//I've taken the node name and dynamically write to the duplicated clips. In the last case i'm not having childelements for the nodeNames I've already make out.
tagName_mc.captionPointer = currentSibling.attributes.title;
yPos += 80;
_root.xmlArray.push(tagName_mc);
}
}
}


and for your problem, could you explian some more. :-)

NovemberRain
November 19th, 2004, 11:19 PM
Thank u very much Johnny64. Pls check the attached file.
I'll explain what i really want

I'm trying to make a family tree with a person as subject (The Main Person). That is we depict each and every members relationship to the subject person. Actually the relationship always goes from top to bottom that we write in the XML file like this. Pegy is the subject person



<g2>
<Pegy title = "Son" />
<Aimy title = "Daughter" />
<Shabu title = "Sister" />
<Jain title ="Mother" />
<Sura title ="Mother" descr = "Madhavi says ....Once again i've a nostalgic longing to go back to those days once again" thumb = "thumbs/person1.jpg"/>
<Norma title ="Daughter" descr1 = "Lakshmi Amma is the famour pperiet afienr dsfjlsdfsfasfdsdfsfdfdsfh asjkf asdjhjkh sdff sdfs fsd fsf" thumbone = "thumbs/person2.jpg"/>
</g2>


From bottom to top Norma is the daugher of Sura and Jain is the mother of Sura and so on. Ok you can see the result while running the FLA file.
The trouble begins here. Norma may have three children. So far no other child nodes in between them. Again for that three childrens we've add one more tags like <g3></g3> to read them. Is it possible to add that under <Norma>'s child nodes and read using the same function that we've written dispTree (); In other words we can reduce the length of XML file and more flexible to handle that. I hope this time things are better that before. Waiting for your reply. Note in The original FLA file the name are different i've mentioned. The names have not much importance until we meet the logical part.

NovemberRain
November 23rd, 2004, 10:40 PM
:( What is up?