0 Replies Latest reply on May 23, 2007 8:37 AM by MikeD.

    XPATH help

    MikeD. Level 1
      I'm trying to write a little game in Flash that uses XML for persistent storage of questions and answers. Our e-learning developers can then reuse the game in various e-learning courses w/out having to do anything in Flash. I developed a "standard" XML format for handling questions and answers (and some additional stuff like hints and feedback), and used this XML format in a JavaScript-based game w/out any trouble (using XPATH to get the relevant data out of the XML file).

      I'm having trouble getting the XPATH statements in ActionScript to work however.

      In JavaScript, I used statements like:

      questionsArray[z]["theText"]= questionNodes.item(z).selectSingleNode("theText").text;
      questionsArray[z]["theHint"]= questionNodes.item(z).selectSingleNode("hint").text;

      , etc, where questionNodes is the XML containing all the questions, to create an array of questions and answers.

      When I try the same statements in ActionScript (using what I think would be the correct ActionScript syntax), I always get null results.

      For example:
      questionsArray[z]["theText"]= XPathAPI.selectSingleNode(questionNodes.item[z], "theText");
      questionsArray[z]["theHint"]= XPathAPI.selectSingleNode(questionNodes.item[z], "hint");

      For that matter, I can never get a trace to put out anything when using item[ ] syntax. For example, the following is undefined:

      trace (questionNodes.item[1]);

      Basically what I'm trying to do is create an array from the XML data, but I can't figure out how to "walk through" the XML data as I can in JS.

      Any ideas? I know the XML is loading properly because I have some other XPATH statements that have worked..

      Thanks for any advice! - Mike