4 Replies Latest reply on May 29, 2007 11:49 AM by Greg Dove

    Understanding XML in Flash

      I have an XML statement that successfully loads the XML file:

      theGameData.load ("game_content_dev.xml");

      Then an XPATH statement that gets all the <question> nodes out of theGameData:

      _global.questionsArrayAll = XPathAPI.selectNodeList(theGameData.firstChild, "/interactionData/module/question[@learningRouletteUsage='yes']");

      I then can trace out the first child node of the first <question> node by using:

      trace (questionsArrayAll[0].firstChild);

      or the last child node using .lastChild

      ... but I can't figure out how to get anyt of the nodes in between. I would have though .childNode[1], childNode[2], etc.. would work but they always return "undefined". I can't figure out an XPATH way of doing this either...

      Any help? The XPathAPI class document is about useless, the only example it lists is using firstChild syntax.

      Thanks! - Mike

        • 1. Re: Understanding XML in Flash
          Greg Dove Level 4
          You're using selectNodeList so I presume you're looking for more than one <question> node. Otherwise you could just use selectSingleNode and it will return the node and not an array of nodes.

          If you want the array and you need to get the childnodes of each element, then just use its childNodes property.

          • 2. Re: Understanding XML in Flash
            Greg Dove Level 4
            And I agree the XPathAPI is a shocker. I was trying to figure out something today too. I couldn't get the AND comparison working for attribute checking. Gave up in the end.
            • 3. Re: Understanding XML in Flash
              MikeD. Level 1
              I'm really struggling with the XPATH part, it's easy in JavaScript as I typically use XML Spy to generate an XPATH statement and then just use it in JavaScript. I've yet to figure out how to do something like the following XPATH statement generated in XML Spy:


              That is, if I have 2 <module> nodes with <question> children, I have no way to get to one or the other.

              It works fine in JavaScript, but not ActionScript.

              I just downloaded the xfactorstudio XPATH api, I'm going to experiment with that now and see if it is something about Flash's simple API that is giving me headaches.

              • 4. Re: Understanding XML in Flash
                Greg Dove Level 4
                Yes, I've not used the xfactorstudio one, but from what I've read its much more comprehensive. The original flash one is very very limited in terms of what's implemented.