pugixml.pugi.XPathQuery

class pugixml.pugi.XPathQuery

Bases: pybind11_object

A compiled XPath expression object.

Examples

>>> from pugixml import pugi
>>> doc = pugi.XMLDocument()
>>> doc.load_string('<node attr="3"/>')
>>> query = pugi.XPathQuery('node/@attr')
>>> query.evaluate_boolean(doc)
True
>>> query.evaluate_number(doc)
3.0
>>> query.evaluate_string(doc)
'3'
>>> node = query.evaluate_node(doc)
>>> bool(node)
True
>>> node.attribute().name()
'attr'
>>> ns = query.evaluate_node_set(doc)
>>> bool(ns)
True
>>> ns.size()
1
>>> ns[0].attribute().name()
'attr'

Methods

__bool__(self)

Determine if this XPath expression is valid.

__init__(*args, **kwargs)

Overloaded function.

evaluate_boolean(*args, **kwargs)

Overloaded function.

evaluate_node(*args, **kwargs)

Overloaded function.

evaluate_node_set(*args, **kwargs)

Overloaded function.

evaluate_number(*args, **kwargs)

Overloaded function.

evaluate_string(*args, **kwargs)

Overloaded function.

result(self)

Return the parsing result.

return_type(self)

Return the return type of the XPath expression.

Member Documentation

__bool__(self: pugixml.pugi.XPathQuery) bool

Determine if this XPath expression is valid.

Returns:

True if XPath expression is valid, False otherwise.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pugixml.pugi.XPathQuery, query: str, variables: pugixml.pugi.XPathVariableSet | None = None) -> None

    Initialize XPathQuery with the XPath expression and variables.

  2. __init__(self: pugixml.pugi.XPathQuery) -> None

    Initialize XPathQuery as an invalid expression.

Parameters:
  • query – The XPath expression.

  • variables – The variables in query. variables can be None.

evaluate_boolean(*args, **kwargs)

Overloaded function.

  1. evaluate_boolean(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XPathNode) -> bool

    Evaluate the expression as a boolean value in the specified context; performs type conversion if necessary.

  2. evaluate_boolean(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XMLNode) -> bool

    Evaluate the expression as a boolean value in the specified context; performs type conversion if necessary.

Parameters:

node – The node to evaluate over.

Returns:

The value evaluated as a boolean, or False if an error occurs.

evaluate_node(*args, **kwargs)

Overloaded function.

  1. evaluate_node(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XPathNode) -> pugixml.pugi.XPathNode

    Evaluate the expression as a node set in the specified context; performs type conversion if necessary.

  2. evaluate_node(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XMLNode) -> pugixml.pugi.XPathNode

    Evaluate the expression as a node set in the specified context; performs type conversion if necessary.

Parameters:

node – The node to evaluate over.

Returns:

The first node evaluated as a node set, or an empty node if an error occurs.

evaluate_node_set(*args, **kwargs)

Overloaded function.

  1. evaluate_node_set(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XPathNode) -> pugixml.pugi.XPathNodeSet

    Evaluate the expression as a node set in the specified context; performs type conversion if necessary.

  2. evaluate_node_set(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XMLNode) -> pugixml.pugi.XPathNodeSet

    Evaluate the expression as a node set in the specified context; performs type conversion if necessary.

Parameters:

node – The node to evaluate over.

Returns:

The value evaluated as a node set, or empty node set if an error occurs.

evaluate_number(*args, **kwargs)

Overloaded function.

  1. evaluate_number(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XPathNode) -> float

    Evaluate the expression as a number in the specified context; performs type conversion if necessary.

  2. evaluate_number(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XMLNode) -> float

    Evaluate the expression as a number in the specified context; performs type conversion if necessary.

Parameters:

node – The node to evaluate over.

Returns:

The value evaluated as a number, or float('nan') if an error occurs.

evaluate_string(*args, **kwargs)

Overloaded function.

  1. evaluate_string(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XPathNode) -> str

    Evaluate the expression as a string in the specified context; performs type conversion if necessary.

  2. evaluate_string(self: pugixml.pugi.XPathQuery, node: pugixml.pugi.XMLNode) -> str

    Evaluate the expression as a string in the specified context; performs type conversion if necessary.

Parameters:

node – The node to evaluate over.

Returns:

The value evaluated as a string, or an empty string if an error occurs.

result(self: pugixml.pugi.XPathQuery) pugixml.pugi.XPathParseResult

Return the parsing result.

Returns:

The parsing result.

return_type(self: pugixml.pugi.XPathQuery) pugixml.pugi.XPathValueType

Return the return type of the XPath expression.

Returns:

The return type of the XPath expression.