So, I’ve been playing with XPath lately. Checked out the implementation at xfactorstudio which is pretty nice.
Then I discovered that the data binding classes have their own xpath implementation right in Flash. You just need to drag a copy of the data binding classes symbol into your library. Do a search for XPathAPI + Flash and you’ll find info on how to use it.
However, every reference I saw to the XPathAPI said it has only two methods: selectNodeList and selectSingleNode. I thought there might be more. A simple for-in loop revealed that there was. So I cracked open ASV and here’s what we have:
static function getEvalString(node, path)
static function selectNodeList(node, path)
static function selectSingleNode(node, path)
static function setNodeValue(node, path, newValue)
static function copyStack(toStk, fromStk)
static function evalExpr(expr, node)
static function filterNodes(nodeList, stack)
static function getAllChildNodesByName(nodeList, name)
static function getChildNodeByName(node, nodeName)
static function getKeyValues(node, keySpec)
static function getPath(node, keySpecs)
static function getPathSet(path)
I won’t post the actual code inside the methods, as I think I’m already on the edge of my EULA. 🙂 But if you are interested, you can play around with these or decompile yourself and see what they do.
I also found it useful to copy the xpath classes into new .as files and put them in my class path. Now I can use them without digging aorund for the data binding class swc each time.