Name

Document.createExpression( ): create an XPath expression for later evaluation — Firefox 1.0, Safari 2.01, Opera 9:

Synopsis

XPathExpression createExpression(StringxpathText,
                                 Function namespaceURLMapper)
    throws XPathException

Arguments

xpathText

The string representing the XPath expression to compile.

namespaceURLMapper

A function that will map from a namespace prefix to a full namespace URL, or null if no such mapping is required.

Returns

An XPathExpression object.

Throws

This method throws an exception if the xpathText contains a syntax error or if it uses a namespace prefix that cannot be resolved by namespaceURLMapper.

Description

This method takes a string representation of an XPath expression and converts it to a compiled representation, an XPathExpression. In addition to the expression, this method takes a function of the form function(prefix) that resolves a namespace prefix string and returns it as a full namespace URL string.

Internet Explorer does not support this API. See Node.selectNodes( ) for an IE-specific alternative.

See Also

Document.evaluate( ), Node.selectNodes( ), XPathExpression, XPathResult

Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.