This content has been marked as final. Show 8 replies
I've just started using the XPathAPI Class for the first time in the last hour or so.
var theXPathString:String = "/interactionData/module/question";
var chosenQuestion= XPathAPI.selectNodeList(this.firstChild, theXPathString);
var pathToTextValue = "question/theText"
var theDataString:String = XPathAPI.selectSingleNode(questionNode, pathToTextValue ).firstChild.nodeValue;
I haven't tested it but I think you might have to do something like that.
I think your problem is your making a string reference to a non-existent array element ------- namely - question
During Parsing place your nodes into an Array then you can reference them directly.
Hope it helps
Looks like you are right, when i changed the XPATH statement to
it worked fine. But I was trying to get the second question, in proper XPATH 2.0 "/interactionData/module/question/theText" would do so without parsing into an array or anything else.
Are you saying when I parse the nodes into an array, I can use XPATH against it? Or I'd have to use that horrible child nodes syntax? When I originally wrote the game, I used crazy statements like the one below (attached code) to get stuff out of an XML array. Now I want to take advantage of XPATH to eliminate this horribly inefficient, inflexible code.
Thanks for your help, I'll keep experimenting!
XPathAPI.selectNodeList returns and array of nodes
childNodes also returns an array of nodes.
so because you can't reference the specific array index in an xpath string with the current implementation in flash, you have stop at the level of your array, then use actionscript array indexing to return the node that you want.
Once you have that node, you can use it with another XPathAPI method... if you want... in your case this was selectSingleNode to get to the theText Node (may not be necessary to use xpath when you're that close... but I did it to provide the example. - and because I'm learning how to use it)
get all <theText> nodes whose parent <question> node has a learningWheelUsage attribute set to "yes".
This is really simple in every other environment that I work in, and I'm thinking it would just be easier to port the game to something else than try to hack together a solution out of Flash's limited implementation.
I'd want to put those into an array of course.. I haven't given up hope yet, I'm going to do some more experimenting, but it is FRUSTERATING!!!!! hahaha..
Thanks for the help!
well I think that might be possible I haven't tried that level of complexity yet.
mytextNodesArr = XPathAPI.selectNodeList(this.firstChild, "/interactionData/module/question[@learningWheelUsage='yes']/theText");
(this is untested in terms of my experience, but I base it on the API documentation)
Also FYI there is a PDF for the documentation here:
Well this test works correctly so you should be able to do what you described with your xml.
Yea, I'm having some success with that example! So exciting, I think I'll take a long lunch.. haha.. Seriously, thanks a lot, I'm on the right track. It's now just a matter of working with the array, I managed to get all the question nodes that I wanted.