PyXdmNode

class PyXdmNode

Bases: PyXdmItem

This class represents a node in the XDM data model. A PyXdmNode is a PyXdmItem, and is therefore a PyXdmValue in its own right, and may also participate as one item within a sequence value. The PyXdmNode interface exposes basic properties of the node, such as its name, its string value, and its typed value.

__getitem__()

Implement the built-in subscript operator (i.e. square brackets []) to return the ith child node of the current node

Returns:

The child node at the specified index. If the child node at the index does not exist returns None.

Return type:

PyXdmNode

attribute_count

Get the number of attribute nodes on this node. If the node is not an element node then returns 0.

Returns:

The number of attribute nodes

Return type:

int

attributes

Get the attribute nodes of this node as a list of PyXdmNode objects

Returns:

List of PyXdmNode objects

Return type:

list[PyXdmNode]

axis_nodes(axis)

Get the array of nodes reachable from this node via a given axis.

Deprecated the argument type for axis will change from Saxon 13 to use the XdmNodeKind enum type Axis options are as follows: ANCESTOR = 0, ANCESTOR_OR_SELF = 1, ATTRIBUTE = 2, CHILD = 3, DESCENDANT = 4, DESCENDANT_OR_SELF = 5, FOLLOWING = 6, FOLLOWING_SIBLING = 7, NAMESPACE = 8, PARENT = 9, PRECEDING = 10, PRECEDING_SIBLING = 11, SELF = 12 :param axis: Identifies which axis is to be navigated. :type axis: int

Returns:

List of PyXdmNode objects

Return type:

list[PyXdmNode]

base_uri

Base URI property. Get the Base URI for the node, that is, the URI used for resolving a relative URI contained in the node. This will be the same as the System ID unless xml:base has been used. Where the node does not have a base URI of its own, the base URI of its parent node is returned.

Returns:

String value of the base uri for this node. This may be NULL if the base URI is unknown, including the case where the node has no parent.

Return type:

str

children

Get the children of this node as a list of PyXdmNode objects

Returns:

List of PyXdmNode objects

Return type:

list[PyXdmNode]

column_number

Get the column number of the node in a source document.

Returns:

The column number of the node, or -1 if not available.

Return type:

int

equals(other)

The equals() relation between two XdmNode objects is true if they both represent the same node. That is, it corresponds to the “is” operator in XPath.

Parameters:

other (PyXdmNode) – The object to be compared

Returns:

true if and only if the other object is an XdmNode instance representing the same node

Return type:

bool

get_attribute_value(name, encoding=None)

Get the value of a named attribute

Parameters:
  • name (str) – the EQName of the required attribute

  • encoding (str) – The encoding of the name argument. Argument can be omitted or None. If not specified then the platform default encoding is used.

get_parent()

Get the current node’s parent. If it does not exist return None.

Returns:

The parent node as a PyXdmNode object, or otherwise None

Return type:

PyXdmNode

get_string_value(encoding=None)

Property to get the string value of the node as defined in the XPath data model

Parameters:

encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

The string value of this node

Return type:

str

head

Property to get the first item in the sequence represented by this PyXdmNode. Since a PyXdmItem is a sequence of length one, this returns the PyXdmNode itself.

Returns:

The PyXdmNode or None if the sequence is empty

Return type:

PyXdmNode

line_number

Get the line number of the node in a source document.

Returns:

The line number of the node, or -1 if not available.

Return type:

int

local_name

Get the local name of the node, as a string

Returns:

the local name of the node. In the case of unnamed nodes (e.g. text and comment nodes) returns None

Return type:

str

name

Get the name of the node, as a string in the form of an EQName

Returns:

the name of the node. In the case of unnamed nodes (e.g. text and comment nodes) returns None

Return type:

str

node_kind

Node kind property.

There are seven kinds of node: documents=9, elements = 1, attributes =2, text=3, comments = 8, processing-instructions = 7, and namespaces=13.

Returns:

an integer identifying the kind of node. These integer values are the same as those used in the DOM

Return type:

int

node_kind_str

‘document’, ‘element’, ‘attribute’, ‘text’, ‘comment’, ‘processing-instruction’, ‘namespace’, ‘unknown’.

Returns:

a string identifying the kind of node.

Return type:

str

Type:

Node kind property string. Returns one of the following

string_value

Property to get the string value of the node as defined in the XPath data model

Returns:

The string value of this node

Return type:

str

to_string(encoding=None)

The string value of the node as returned by the toString method

Parameters:

encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

String value of this node

Return type:

str

typed_value

Get the typed value of this node, as defined in the XPath data model

Returns:

the typed value. If the typed value is a single atomic value, this will be returned as an instance of PyXdmAtomicValue

Return type:

PyXdmValue