12 Replies Latest reply on Jun 26, 2007 10:06 AM by Greg Dove

    Problem with XFactor XPATH api statement

      Given the little XML snippet below (attached code), the following XPATH statement using XFactor Studio's XPATH works fine if both <question>'s are in the same <topic>, but as soon as I introduce multiple <topic> nodes, I get jumbled results.

      _global.questionsArrayAll = XPath.selectNodes(theGameData.firstChild, "//question[@gameUsage='yes']");

      Does anything jump out at anyone as being wrong? I thought // always caused a "start at root and get anything at any level" in XPATH...

        • 1. Re: Problem with XFactor XPATH api statement
          MikeD. Level 1
          I hate, hate, hate bumps and apologize profusely, but I'm really stuck on this and I'm hoping someone can give me some help, or at least point me to somewhere that I may find an XFactor Studio guru/support person at...

          Thanks a lot!
          • 2. Re: Problem with XFactor XPATH api statement
            injpix Level 3
            I dont know how XFactor Studio syntac would be but try one of those lines of code below. I hope that helps, I have banged my head on using Flash's built in Xpath today.
            • 3. Re: Problem with XFactor XPATH api statement
              MikeD. Level 1
              Unfortunately, none of these work. Or at least, don't fix my problem. I'm starting to think my problem is more complex than I thought though.

              It appears my original XPATH statement (and at least one of yours) gets the XML out fine, if I trace it out. I think the problem is either when I'm loading the XML into an array, or when I go to put it out of the array into text boxes. I'm just not sure. It's weird though, since the whole thing works perfectly if there is only one <topic> containing all the <question> nodes.

              I'm attaching the code to load the XML into an array.

              Again, if there is only one <topic>, this works fine and the trace at the end properly puts out the text of the question. However, if there are multiple <topic>'s containing <question>'s, I get an undefined error in the trace during the SECOND time through the loop. It puts out the text of the first <question>, but undefined on the second...

              • 4. Re: Problem with XFactor XPATH api statement
                MikeD. Level 1
                By chance, does anyone know how to contact the person/people responsible for the XFactorStudio XPATH API? The website just has a link to download it...

                • 5. Problem with XFactor XPATH api statement
                  Greg Dove Level 4
                  Just a quick check.. probably not necessary... can you confirm that your <topic> nodes are inside another node? You say in your original post that its an xml "snippet"... so hopefully that is the case.

                  You can't have more than one topic node at the root level of your xml document if that's what you have... an xml document has to have one single "root" node which contains everything else. This may not be relevant... but just in case!
                  • 6. Problem with XFactor XPATH api statement
                    MikeD. Level 1
                    That's a good point, but yes, in the full XML structure the <topic> node is not the root node. It's actually something more like the following, where <interactionData> is the root node:

                    <scavengerHunt title="This appears in the title area of your interaction, if you have one" passingScore="70" passingMeasurment="percent">
                    <!-- reserved for other Scavenger Hunt specific info -->
                    <learningRoulette title="This appears in the title area of your interaction, if you have one" passingScore="60" passingMeasurment="points">
                    <!-- reserved for other Learning Wheel specific info -->

                    <question type="multipleChoice" gameUsage="yes">
                    <theText>What color is blue?</theText>
                    <response correct="yes">Blue</response>
                    <response correct="no">Red</response>
                    <response correct="no">Green</response>
                    <feedbackIncorrect>Not quite. Blue is blue</feedbackIncorrect>
                    <hint>Not red or green, that is for sure!</hint>


                    <question type="multipleChoice" gameUsage="yes">
                    <theText>What number is 10?</theText>
                    <response correct="yes">10</response>
                    <response correct="no">9</response>
                    <response correct="no">11</response>
                    <feedbackIncorrect>Not quite. It is 10</feedbackIncorrect>
                    <hint>Between 9 and 11</hint>


                    Thanks for the reply! - Mike
                    • 7. Re: Problem with XFactor XPATH api statement
                      Greg Dove Level 4
                      OK... I've been meaning to use Xfactorstudios xpath before I start doing work in as3... haven't used it yet.... so I'll d/l and see if I can replicate your problem.

                      I'll also try it using adobe's (minimal) version of xpath and check that out.

                      I'll use exactly the same as the xml example you posted above ...but with the interactionData tag at the end closed... ;-)

                      will post back results soon.
                      • 8. Re: Problem with XFactor XPATH api statement
                        MikeD. Level 1
                        Woops, I saw in my first paste that I hadn't grabbed the end tag, so I copy/pasted the start tag, but forgot to add the slash to make it an end tag... Anyway, in my XML file, it is properly closed... :-)

                        As a matter of fact, I have the XML file in XML Spy, I used XML Spy to generate the XPATH statement. It works there, and it worked when I developed a different game in JavaScript, but not in ActionScript...

                        Please let me know if you need any other clarification...

                        Thanks! - Mike
                        • 9. Re: Problem with XFactor XPATH api statement
                          MikeD. Level 1
                          Oh, this might be helpful. The following is my entire "FillArrays" function that I use when the XML data is loaded.

                          I just realized that since I began this project, I'd renamed an attribute in the <question> element. It use to be "gameUsage" (and is in the XML snippet above). It is now learningRouletteUsage, since the XML file is now designed to store questions for numerous "learning games".

                          function fillArrays () {

                          XPath.selectNodes(theGameData.firstChild, "//question[@learningRoulette=\"yes\"]");

                          questionsArrayAll = XPath.selectNodes(theGameData.firstChild, "//question[@learningRouletteUsage=\"yes\"]");

                          //trace (_global.questionsArrayAll);

                          _global.questionsArray = new Array(questionsArrayAll.length);

                          _global.numOfQuestions = questionsArrayAll.length;
                          _global.questionCounter = 0;

                          for (z=1;z<questionsArrayAll.length + 1; z++) {
                          questionsArray[z] = new Object();
                          questionsArray[z].theText = XPath.selectSingleNode(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/theText");

                          questionsArray[z].rightAnswer = XPath.selectSingleNode(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/response[@correct='yes']");
                          questionsArray[z].feedbackCorrect = XPath.selectSingleNode(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/feedbackCorrect");

                          questionsArray[z].feedbackIncorrect = XPath.selectSingleNode(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/feedbackIncorrect");

                          questionsArray[z].hint = XPath.selectSingleNode(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/hint");

                          questionsArray[z].additionalInstructions = XPath.selectSingleNode(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/additionalInstructions");

                          questionsArray[z].haveIbeenAnsweredYet = "No";
                          numOfResponses = XPath.selectNodes(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/response").length;

                          questionsArray[z].theNumberOfResponses = numOfResponses;
                          questionsArray[z].wrongAnswers = XPath.selectNodes(theGameData.firstChild, "//question[" + z + "][@learningRouletteUsage='yes']/response[@correct='no']");

                          trace (questionsArray[z].theText + " and z is: " + z);

                          _global.myArrayOfQuestions = {};
                          _global.myArrayHasPlayed = {};
                          _global.counterVar = questionsArrayAll.length;
                          // this initializes all questions as not having been played...
                          for ( var i=0; i<counterVar; i++ ) {
                          _global.myArrayHasPlayed = false;

                          } //end the fillArray function...
                          • 10. Re: Problem with XFactor XPATH api statement
                            Greg Dove Level 4
                            I just got back from testing and saw your additonal posts. I have a version that is working... and what I'm hoping is that you'll be able to use it as a guide.

                            I didn't try Adobe's xpath in the end... but it took a while to find some documentation for xpath. (I ended up going to this site:
                            to find the "text()" part which returns the value of the text node )

                            Anyhow... with the original example xml (gameusage="yes" you posted above), this works... and I think its what you're trying to do in terms of populating the array...if not let me know. I saved the xml with the name 'tester.xml'.

                            NB.. there were no "additionalInstructions" in that xml example...so it returns undefined. Guess you have that in your new xml.

                            You should be able to change gameUsage to learningRouletteUsage in line 22.

                            • 11. Re: Problem with XFactor XPATH api statement
                              MikeD. Level 1
                              This is looking promising! I see the logic of what you are doing there.

                              I just was looking at my JavaScript game to see what is different (logically, not syntatically) and it looks like I was doing the same thing as what you did. That is, I had a nested loop that was looking at each individual <question>.. I just didn't read my own code carefully enough.. haha

                              Thanks a lot!
                              • 12. Re: Problem with XFactor XPATH api statement
                                Greg Dove Level 4
                                You're welcome.

                                I'm no expert in this stuff, but I've been using the adobe xpath recently so its kind of fresh in my mind. Please don't assume the way I did it is the best way - its just the way I happened to do it. I'm sure you could do it by creating the right string references as an xpath argument as well.