That's because you're searching from the country-node, that's the
structure you're searching in. Forget about all its parentnodes, we're
talking about a new xml-document here.

var countriesList:Array = XPath.selectNodes(xmlData, "/map/country");

for (var i=0; i<countriesList; i++) {
var countryName:XMLNode = XPath.selectSingleNode(countriesList[i], "name");
   trace(countryName);
}

// -- this should give the same results since xmlData is the source
var countryNames:Array = XPath.selectNodes(xmlData, "/country/name");
trace(countryNames);

I was following the thread, but don't anderstand the answer.
I was sure it was a problem of context, but I don't get how to fix it.
Your explanation is clear but doesn't follow the first example provided :

function parseXML(xmlData) {
        countriesList = XPath.selectNodes(xmlData, "/map/country");
handleCountry (countriesList [0]);<----------- seems to sends a new context node
}

function handleCountry(country) {
countryName = XPath.selectNodes(country, "/country/name"); <---- why not root node of the new context here ?
        trace(countryName);     // shows nothing        

        // If I do this though, I get back the original results
countryList = XPath.selectNodes(country, "/map/country"); <------ still evaluating xmlData there ?
        trace(countryList);     // shows country list
}

Perhaps it's because of references.
"country" is an XMLNode passed by reference to handleCountry
Then, when XPath tries to filter from country's context, it uses in fact the same XMLdocument as before.

I am not really happy  with this explanation though.
Further explanation ?


Thanks.

-----------
erixtekila
http://blog.v-i-a.net/

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to