View comments | RSS feed

XPathAPI class

ActionScript Class Name mx.xpath.XPathAPI

The XPathAPI class allows you to do simple XPath searches within Macromedia Flash. This can be very useful for searching XML packets based on node names and attribute values. In other words, you can quickly find nodes and attributes in an XML document using the XpathAPI methods.

In order to use XPath searches within Flash, you first need to include the XPathAPI class into your Flash library by adding the DataBindingClass (if it hasn't been added already). If you've already set up bindings, this class may have been included automatically; otherwise, you need to select the class from the common libraries (Window > Common Libraries > Classes). From the Classes.fla library panel, you can simply drag a copy of the DataBindingClasses component into your current Flash document's library. Now, you can import the class by typing import mx.xpath.XPathAPI or by using the classes fully qualified name when accessing its methods by prefixing the class methods with mx.xpath.XPathAPI.method_name.

For more information about this class, see the Flash Documentation Resource Center at www.macromedia.com/go/xpathapi.


Version 8

Comments


2Khcd said on Feb 10, 2006 at 5:31 PM :
In order TO USE XPath searches within Flash, you have to do ONLY ONE THING:
import the class by typing:

// SCRIPT
import mx.xpath.XPathAPI;
// END SCRIPT

or by using the classes fully qualified name when accessing its methods by prefixing the class methods with
mx.xpath.XPathAPI.method_name.

!! IMPORTANT: you DON'T HAVE TO import into your library DataBindingClasses component from Classes.fla (Window > Common Libraries > Classes)

----
by: 2K [Marek Skopowski, Nowa Huta, Cracow, Poland] from IAMedia, Inc. [2K hARDcORE Design, 2006]
jdehaan said on Feb 13, 2006 at 11:20 AM :
Thank you for noting this - I have filed this as a bug for the writer to update the content (available in a future Help update).

Users please note that this does not apply to Flash MX 2004 - this note only applies to Flash 8 content. If you do not have the classes in your library in Flash MX 2004, your code will not work.
Chris Manuel said on Apr 10, 2007 at 2:20 PM :
When using XPathAPI.getEvalString(xmlObject, path) note that the string
that is returned uses this syntax:

.childNodes.0.childNodes.1.firstChild.nodeValue (just and example)

Normally, in Flash you would see:

.childNodes[0].childNodes[1].firstChild.nodeValue

If you want to use the result from the XPath getevalString to get to an
element you will need to use the following syntax:

eval("xmlObject.childNodes.0"+theResultFromXPath_API.getEvalString)

If you try eval("xmlObject.childNodes[0]"+theResult) it will return
undefined.

I'm sure there's a logical reason but it stumped me for awhile.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00004322.html