4Suite™ API Documentation

# ► Module Ft.Xml.XPath

4XPath initialization and principal functions
Copyright 2005 Fourthought, Inc. (USA).
Detailed license and copyright information: http://4suite.org/COPYRIGHT
Project home, documentation, distributions: http://4suite.org/

Classes: CompiletimeException, RuntimeException, XPathException |  |  |  | Functions: Compile, Evaluate, NormalizeNode, SimpleEvaluate |  |  |  | Fields: FT_EXT_NAMESPACE, NAMESPACE_NODE, XPATH_NAMESPACE_NODE

## Modules

Context | The context of an XPath expression
Context | The context of an XPath expression
g_parser |
parser |

## Classes

class CompiletimeException(XPathException)
The exception raised when an error is encountered during the parsing or compilation of an XPath expression.

### Methods

__init__(self, errorCode, *args)

### Methods inherited from class Ft.FtException

__getattr__, __repr__, __str__

### Methods inherited from class exceptions.Exception

__getitem__

### Fields

INTERNAL = 1
SYNTAX = 2

class RuntimeException(XPathException)
The exception raised when an error is encountered during the parsing or evaluation of an XPath expression.

### Methods

__init__(self, errorCode, *args)

### Methods inherited from class Ft.FtException

__getattr__, __repr__, __str__

### Methods inherited from class exceptions.Exception

__getitem__

### Fields

ARGCOUNT_ATLEAST = 202
ARGCOUNT_ATMOST = 204
ARGCOUNT_EXACT = 203
ARGCOUNT_NONE = 201
INTERNAL = 1
NO_CONTEXT = 10
UNDEFINED_FUNCTION = 102
UNDEFINED_PREFIX = 101
UNDEFINED_VARIABLE = 100
WRONG_ARGUMENTS = 200

class XPathException(Ft.FtException)
Base class for exceptions specific to XPath processing

### Methods

__init__(self, errorCode, messages, args)

### Methods inherited from class Ft.FtException

__getattr__, __repr__, __str__

### Methods inherited from class exceptions.Exception

__getitem__

## Functions

Compile(expr)
Given an XPath expression as a string, returns an object that allows an evaluation engine to operate on the expression efficiently. This "compiled" expression object can be passed to the Evaluate function instead of a string, in order to shorten the amount of time needed to evaluate the expression.
Evaluate(expr, contextNode=None, context=None)
Evaluates the given XPath expression.
Two arguments are required: the expression (as a string or compiled
expression object), and a context. The context can be given as a
Domlette node via the 'contextNode' named argument, or can be given as
an Ft.Xml.XPath.Context.Context object via the 'context' named
argument.
If namespace bindings or variable bindings are needed, use a
Context object. If extension functions are needed, either use a
Context object, or set the EXTMODULES environment variable to be a
':'-separated list of names of Python modules that implement
extension functions.
The return value will be one of the following:
node-set: list of Domlette node objects (xml.dom.Node based);
string: Unicode string type;
number: float type;
boolean: Ft.Lib.boolean C extension object;
or a non-XPath object (i.e. as returned by an extension function).
NormalizeNode(node)
NormalizeNode is used to prepare a DOM for XPath evaluation.
1. Convert CDATA Sections to Text Nodes.
2. Normalize all text nodes (adjacent nodes are merged into the first one).
SimpleEvaluate(expr, node, explicitNss=None)
Designed to be the most simple/brain-dead interface to using XPath Usually invoked through Node objects using: node.xpath(expr[, explicitNss])
expr - XPath expression in string or compiled form
node - the node to be used as core of the context for evaluating the XPath
explicitNss - (optional) any additional or overriding namespace mappings
in the form of a dictionary of prefix: namespace
the base namespace mappings are taken from in-scope
declarations on the given node. This explicit dictionary
is suprimposed on the base mappings

## Fields

FT_EXT_NAMESPACE = 'http://xmlns.4suite.org/ext'
NAMESPACE_NODE = 13
XPATH_NAMESPACE_NODE = 13