|
|
|
#1 |
|
Senior Member
Join Date: Jun 2006
Posts: 100
|
[RESOLVED] XML Tree question
Hi, I had a question which relates to loading a complex XML file into flash.
Lets say I had an XML file which looked like this: PHP Code:
How would I specifiy the level which contains the "dog" info? What I mean by this is do I say "this.firstChild.childNodes" or... this is the part I am confused by. I do not understand how to tell flash where to look for info when it loads the xml file. Let me know if you need clarification. Thanks in advance, - Peter |
|
|
|
|
|
#2 |
|
Student
Join Date: Apr 2001
Location: -
Posts: 4,756
|
lets say your xml file is called "xml_file.xml",
this code on the first frame of the flash movie wich is saved in the very same folder as your xml file: PHP Code:
maybe this post from today helps as well: http://board.flashkit.com/board/showthread.php?t=737052
__________________
my new home: polycount old: Curing C. tech | Curing C. designs | tank | ortho. | zelda LTTP | Tile Edit. | scrolling 3d: 3d engine kit | ASE format | 3d binary format |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2006
Posts: 100
|
Many thanks, that was exactly what I was looking for.
|
|
|
|
|
|
#4 |
|
Student
Join Date: Apr 2001
Location: -
Posts: 4,756
|
some explaination the variables I wrote:
a.) - first you call the xml object in this case "xml" - because each XML file has to start with only 1 node you have to enter that one (the <data> one) with ".firstChild" - now you are in the first Child <data> to gain access to the child nodes it´s the easiest way to convert the childNodes to an array for faster handling using "childNodes" - what follows are the brackets [0] and the Child number (an array starts always with 0 so the 1st child would be 0 and the last one last-1) ,- so the code ".childNodes[0]" tells AS to take the first CHild from the childNodes of the node that stands before this part. - because you have another hierarchy (thus gooing deeper) we need to repeat the last 2 steps again to go deeper into the hierarchy but in this case we need the 2nd child of those childNodes (remember first = 0, 2nd = 1,...) thus the code is "childNodes[1]." - to finally read out the attribute of that node use the command "attributes." followed by your attribute name from the xml file in your case "name" but it could be as well "desc" or "id" b.) follows the same pattern as a.) c.) this is an alternative way without using the childNodes command (wich converts the nodes to an easy array object)- usually this results in very big code but it is also possible doing it this way. - call the xml object "xml" - goto the first Child <data> using "firstChild." - from that node go again into the first Child wich would be <flower> using "firstChild." - again go into the first child even though we need the 2nd child and not the first child. This is because we need to enter that hierarchy anyway before we can switch to another sibling- so firstChild is also used to enter nodes. - since we have the 1st child and not the 2nd one use now "nextSibling" to go to the next Sibing (2nd node where we want to go) - call the method "attributes" followed by your attribute name "name" to access your variable d.) follows same pattern as c.)
__________________
my new home: polycount old: Curing C. tech | Curing C. designs | tank | ortho. | zelda LTTP | Tile Edit. | scrolling 3d: 3d engine kit | ASE format | 3d binary format |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jun 2006
Posts: 100
|
thanks for the in depth, but the only part I was confused with was the " xml.firstChild.childNodes[0]childNodes[1].attributes.name;" part.
My final code ended up as:
There was a minor change to the XML. Where "desc" was became "url". Last edited by SilverVenom; 07-22-2007 at 08:55 AM. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jun 2006
Posts: 967
|
*snip*
Sorry, I decided to post my question as a new thread instead of burying it in a [resolved] thread. Last edited by Alluvian; 07-27-2007 at 11:53 AM. |
|
|
|
![]() |
|
||||||
| Thread Tools | |
| Display Modes | |
|
|