Xpath in ActionScript 2.0


Yet again I have been given job to create a Flash component that will be displayed on homepage of site, and it has to list all content of site. For this I ask for a XML backend that provide the data to Flash. Since we have lot of data I opt to use XPath API of Actionscript to find and parse XML data in flash. This can be done using DataBindingClass provided in Flash 8 under Classes. This add a hidden library for XML Xpath to your project. Once you does that simply import the following:

mx.xpath.XPathAPI

 in your Actionscript to have the XPath API enable for you. You can find more information about this in Flash Help file but some major functions are:

XPathAPI.selectNodeList(object/mc,”xpath”);

XPathAPI.selectSingleNode(object/mc,”xpath”);

the above return XML node object array where as later returns the node only.

Hope that help as quick guide… will post sample code later someday 🙂

EDIT: if you need to read a attribute in any node (not searching but reading the attribute value) then simply append the .attributes  [“attributename”] to your selectSingleNode or selectNodeList array element.

,