From http://code.google.com/p/xpath-as3/
An XPath implementation for ActionScript 3.0.
XPath-AS3 can be used in any AS3 project, including:
GettingStarted
Basic overview of how to use the XPath library
Executing XPath Statements
XPath queries are evaluated using the XPathQuery object.
// create the XPathQuery instance and parse the pathvar myQuery:XPathQuery = new XPathQuery("path/to/evaluate");// execute the statement on an XML object and get the resultvar result:XMLList = myQuery.exec(myXML);
Using namespaces
var myQuery:XPathQuery = new XPathQuery("ns1:path/to/ns2:evaluate");myQuery.context.namespaces["ns1"] = "http://domain.com/2006/ns1";myQuery.context.namespaces["ns2"] = "http://domain.com/2007/ns2";
Short-hand Namespace handling
var myQuery:XPathQuery = new XPathQuery("ns1:path/to/ns2:evaluate");myQuery.context.useSourceNamespacePrefixes = true;
// no need for prefixes in this statementvar myQuery:XPathQuery = new XPathQuery("path/to/evaluate");myQuery.context.openAllNamespaces = true;
The XPathContext object
// create the context instancevar context:XPathContext = new XPathContext();// declare a namespacecontext.namespaces["ns1"] = "http://domain.com/2006/ns1";// define a custom variablecontext.variables["myCustomVar"] = true;// Pass the context to the XPathQuery instancevar myQuery:XPathQuery = new XPathQuery("path/to/evaluate", context);
// this namespace will be available to all XPathQuery objectsXPathQuery.defaultContext.namespaces["ns1"] = "http://domain.com/2006/ns1";
Extending XPathContext
public class MyContext extends XPathContext { public function MyContext(){ // add the custom functions to the functions table functions['custom-function'] = customXPathFunction; }
// custom XPath functions must receive a reference to the // context as their first argument. You may have any number of other // arguments of any type, and the return value can be any type. private function customXPathFunction( context:MyContext, arg1, arg2.. ):String { // add code here }
// extensions to MyContext must implement copy() public override function copy():XPathContext { var clone:MyContext = new MyContext(); // use the utility method to make sure that all the built-in and // internal properties are copied copyProperties( clone, this ); return clone; }}
var path:String = "path/to/evaluate[@att = custom-function(1,2)]";var myQuery:XPathQuery = new XPathQuery(path, new MyContext());
xpath-as3-1.0.0.zip
SVN location
0 comments:
Post a Comment