Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

burst.xml.XPath Class Reference

List of all members.

Detailed Description

Class representing a complied XPath expression.

We support a simplified xpath syntax. The path contains 1 or more of the following, separated by '/', such as:

para children named 'para' para[5] just the 5th child named 'para' (1-based) * all element children text() all text node children

The beginning of a path can be:

nothing, just start with the provided context node . same as nothing (start with context node), but useful to prefix // / start from document and ignore context node // look for the next path segment to begin any number of levels below context node

In the middle of the path there can be:

// go to all descendants

Not supported:

When there is a fast real XPath implementation available, use that instead.

See Also

Simplified XPath Languages

For other attempts at simplifying XPath for various purposes, see for example:

Less than XPath in browsers

Starting with MSXML 2 (IE5.5+), IE has Node.selectNodes(expr) and Node.selectSingleNode(expr) which can be used on XML documents for example from XMLDOM or XMLHTTP. There are installation/version complexities as to whether the expression language is true XSLT or not; generally speaking, MSXML2 (IE5.5) is Microsoft's language, and MSXML3 (IE6) is standard.

Mozilla implements part of DOM Level 2 Traversal: It implements TreeWalker and NodeFilter, but no NodeIterator so far.

Full XPath in browsers

In .NET, Microsoft there is a full XPath implementation including a family of interfaces such as XPathNodeIterator, XPathNavigator, XPathDocument, XPathExpression. (Note that XPathDocument (XPathDocumentIterator) and XmlDocument (DocumentXPathNavigator) both implement IXPathNavigable but XPathDocument has a more efficient implementation for XPath queries. Also re-using XPathNodeIterator instances avoids redundant expression compilation.) An example is:

XPathNavigator nav = new XPathDocument(file).CreateNavigator(); XPathExpression expr = nav.Compile('//bar[@name="id17"]'); XPathNodeIterator nodes = nav.Select(expr);

In Mozilla (including Netscape 7) there is an implementation of the W3 DOM Level 3 XPath: This module has among other functions: doc.evaluate(DOMString expression, Node contextNode, XPathNSResolver resolver, unsigned short type, DOMObject resultexpr) This can be used if you have a DomDocument (from XMLHttpRequest responseXML or createDocument). Other interfaces include XPathException, XPathEvaluator, XPathExpression, XPathNSResolver, XPathResult, XPathNamespace. An example is:

var some_bar_node = xmlDocument.evaluate('//bar[@name="id17"]', xmlDocument, null, 9, null).singleNodeValue; var idval = some_bar_node.getAttribute("name"); // idval should now be == 'id17'

Public Member Functions

 XPath (String pathstr, String flags)
 A function to return a burst.xml.XPath object.

void iterate (Node node, Function func)
 Call the function for each match to the path, using the provided node as the context node.

Node selectSingleNode (Node node)
 Returns the first matching node, or undefined if none.

Array selectNodes (Node node)
 Collect all matches and return them as an Array.

Constructor & Destructor Documentation

burst.xml.XPath.XPath String  pathstr,
String  flags

A function to return a burst.xml.XPath object.

Internally it can be used as a constructor, but it should be called as a function so that we can cache compiled XPath instances based on the arguments.

The flags supported are:

  • 'h', assume an HTML DOM, which means that all names returned by the DOM are in all uppercase

Note that we assume that the HTML DOM tagName and nodeName always return uppercase; we leave their return values unchanged, and just uppercase our strings before comparing.

If flags are not provided (undefined), we default to 'h'.

do all browsers return uc for tagName and nodeName? do they do it even on xhtml doctype, or mime type text/xml?

Member Function Documentation

void burst.xml.XPath.iterate Node  node,
Function  func

Call the function for each match to the path, using the provided node as the context node.

If the function returns true, iteration stops.

If the path is absolute, then the node argument is irrelevant and can be null.

node The context node
func The callback function

Array burst.xml.XPath.selectNodes Node  node  ) 

Collect all matches and return them as an Array.

See selectNodes: Unlike Microsoft selectNodes, our result is not a "live" collection, but a static snapshot.

node The context node

Node burst.xml.XPath.selectSingleNode Node  node  ) 

Returns the first matching node, or undefined if none.


node The context node

The documentation for this class was generated from the following file:
Generated on Tue Nov 30 04:03:09 2004 for BurstProject by doxygen 1.3.4