« Macromedia Flash Player 7 for Linux now available | Main | Talk between Javascript and Flash »

June 07, 2004

XPath in Flash

XPath4AS2 is an ActionScript 2 library to add XPath functionality to Flash.

What is XPath?
XPath is a concise language for selecting nodes from an XML document. It allows you to write a short string query that defines a path to the nodes you want to select. For example, if you had a document that looks like this:

<products>
	<product SKU="7123734">

<name>Big Metal Pot</name>
<price>19.95</price>
</product>

<product SKU="752585">
<name>Plate</name>

<price>12.95</price>
</product>
<product SKU="4182476">

<name>Spoon</name>
<price>4.95</price>

</product>
</products>

You could select an array of products with this query
myXPathDocument.selectNodes("/products/product");

You could get all products that cost more than $5.00 like this
myXPathDocument.selectNodes("/products/product[./price > 5]");

You could get an array of all the SKUs with this
myXPathDocument.selectNodes("/products/product/@sku");

XPath is a very powerful language that can greatly simplify working with XML documents.

( As found in http://www.xfactorstudio.com/Actionscript/AS2/XPath/)

The AS 1 implementation of the same can be found at http://www.xfactorstudio.com/Actionscript/AS1/XPath/

Read more about XPath for Flash here.

You can dowload it here.

Posted by kp at June 7, 2004 04:57 AM

Trackback Pings

TrackBack URL for this entry:
http://www.lastashero.com/blog/mt-tb.cgi/4

Comments

Post a comment




Remember Me?

(you may use HTML tags for style)