Download the files here.
TUTORIAL CONTENTS
  • Introduction
  • Flash/XML Syntax
  • Accessing nodes
  • Digging deeper
  • Power of Attributes
  • HTML and Text in XML
  • Making a Search Engine
  • Preloading XML files
  • XML/FLASH SITES AND TUTORIALS
  • Tupps web site
  • Flash 5 and XML
  • XML Table Constructor Kit
  • Using an XML file to load Chart components
  • Macromedia XML tutorial
  • Integrating XML and Flash in a Web Application
  • AUTHOR´s XML TUTORIALS/FILES
  • XML searchable database I
  • URLs and Asfunctions (II)
  • XML searchable database III
  • XML database Component
  • XML slideshow Component
  • XML scroller menu Component
  • Flash - XML Tutorial

    Accessing nodes

    Our previous example for xml was very simple. This is ok to explain what XML is but in many cases it is not realistic, because databases are very large with different data and therefore much more complex with substructures. So let´ look at a more complex XML file, which we will develop further and finally create a simple search engine. I will not post the whole XML file here but instead click on the link to see the file. The structure more simplified is like this:

                       <?xml version="1.0"?>
                        <models>   //childNodes from here on
    	                    <female>                          //firstChild
    		                     <black>                      //firstChild.firstChild
                                      <susan>                 //firstChild.firstChild.firstChild
                                       Susan Black                  //textnode or nodeValue
                                       age: 21
                                       eye color: dark blue
                                       hair color: black
                                       foreign language: german
    			                       </susan>
    	                               more nodes here              //firstChild.firstChild.nextSibling
    		                     </black>
    		                     <blond>
                                       more nodes here		
    		                     </blond>
    	                     </female>
    	                     <male>                           //lastChild
    		                     <black>                      //lastChild.firstChild
                                       more nodes here
    		                     </black>
    		                     <blond>
                                       more nodes here
    		                     </blond>
    	                      </male>
                          </models>
    

    We have of course as you have seen more textnodes, which I have omitted for simplification here. I have indicated the location of all the individual nodes here. All nodes are basically childnodes of the rootnode. So one possibility is to attack each node individually, but imagine what kind of code work that is to write child of child of .... . So the way to do this is by using loops, which will go through all the children that we can easily grab those nodes we want. In the following the script is shown to get to the female or male node.

                                   function listItems(myItem01) {
                                        for (var count01 in myItem01.childNodes) {
    		                                 modelList = myItem01.childNodes[count01].nodeName;
                                             if (modelList == inputTextfield.text) {
    			                                  idList = myItem01.childNodes[count01];
    			                                  mainField.htmlText = idList;
    			                                  textField1.htmlText = idList.firstChild;
    			                                  textField2.htmlText = idList.firstChild.firstChild;
    			                                  textField3.htmlText = idList.firstChild.firstChild.nextSibling;
                                              }		 	
                                         }	
                                   }
    

    The first part of the script I have omitted because it is basically identical to the previous script to load the XML file. The main part in this script is the for ... in ...loop. We loop through the XML file childNodes of the root node, whose nodeName is male and female. the var count01 counts the number of childNodes, which are 2 (0 and 1) in this case. After looping we create the var modelList, which holds the different nodeNames (myItem01.childNodes[count01].nodeName). Then in the next if statement we ask for the nodeName, in this case we will type the nodeName into an input textfield. If female then all the female childnodes as held in the var will be shown. Before we continue let´s see the real live example below.

    Let´s see some of the terms. We already know firstChild. There is of course also lastChild. Then in case we have equal childnodes following the firstChild they are all nextSiblings or depending on their position previousSiblings. And now we are a whole step further.

    In the next lesson we will go a little bit deeper into the XML file. It is actually not so much new but here you learnt a lot, which you have to digest first with another example.


    PREVIOUS          NEXT