looping through childNodes

  • BardicKnowledge
  • Novice
  • Novice
  • BardicKnowledge
  • Posts: 21
  • Loc: Halifax

Post 3+ Months Ago

Hey,
I have a XML problem which I just can't figure out. After failing several times I found a tut on Kirupa and it seems to me I'm doing it the same way. The only difference is mine doesn't work.

I won't paste all my code but just the XML. If the rest is needed just let me know and I can post it:

AS
Code: [ Select ]
var container_xml:XML = new XML();
container_xml.onLoad = startXML;
container_xml.load("container_xml.xml");
container_xml.ignoreWhite = true;

function startXML(success){
    if (success == true){
        rootNode = container_xml.firstChild
    }
}

........

xmlLength = rootNode.childNodes;
    for(i=0;i<xmlLength.length; i++){
        currentNode = xmlLength[i];        
        
        xmlLength = rootNode.currentNode.childNodes;        
        for(ii=0;ii<xmlLength.length; ii++){            
            firstKid = xmlLength.firstChild;
            heightOffSet = parseInt(firstKid.firstChild);
            centerOffSet = parseInt(firstKid.nextSibling.firstChild);
        }    
    }
  1. var container_xml:XML = new XML();
  2. container_xml.onLoad = startXML;
  3. container_xml.load("container_xml.xml");
  4. container_xml.ignoreWhite = true;
  5. function startXML(success){
  6.     if (success == true){
  7.         rootNode = container_xml.firstChild
  8.     }
  9. }
  10. ........
  11. xmlLength = rootNode.childNodes;
  12.     for(i=0;i<xmlLength.length; i++){
  13.         currentNode = xmlLength[i];        
  14.         
  15.         xmlLength = rootNode.currentNode.childNodes;        
  16.         for(ii=0;ii<xmlLength.length; ii++){            
  17.             firstKid = xmlLength.firstChild;
  18.             heightOffSet = parseInt(firstKid.firstChild);
  19.             centerOffSet = parseInt(firstKid.nextSibling.firstChild);
  20.         }    
  21.     }


XML
Code: [ Select ]
<root>
    <container a="container">
        <h>10</h>
        <o>0</o>
    </container>
</root>
  1. <root>
  2.     <container a="container">
  3.         <h>10</h>
  4.         <o>0</o>
  5.     </container>
  6. </root>



I think the problem is that currentNode = xmlLength[i]; is equal to more than just that child name, but to everything within the container child.

Any one see what I'm doing wrong?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

The code outside of the onload needs to be inside of the onLoad, and you redeclare xmlLength inside of a for loop. Make the second xmlLength a different variable name.
  • BardicKnowledge
  • Novice
  • Novice
  • BardicKnowledge
  • Posts: 21
  • Loc: Halifax

Post 3+ Months Ago

Thanks for the reply and I will try that tomorrow. I forgot my files at work >.<

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 23 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.