axl main logo

axl.Node — PyAxlNode class: XML node instance

Intro

axl.Node class represents a single node instance that is hold by a document (axl.Doc).

The usual operation is to load a document and the acquire a reference to the node inside as follows:

# load the document
(doc, err) = axl.parse ("<root-node><child /></root-node>")
if err:
   print ("Failed to parse content: " + err.msg)
   return -1

# get the <child> node
node = doc.get ("/root-node/child")

However, you can also create new nodes using the type constructor of axl.Node as follows:

# set a new root node
doc.root = axl.Node ("test")

Module API

class axl.Node
next_called(node_name)

Allows to get the next node on the same level or the instance node, but with the provide name.

Parameters:node_name (String) – node name to match.
Return type:Returns an instance of axl.Node or None if no node was found.
previous_called(node_name)

Allows to get the previous node on the same level or the instance node, but with the provide name.

Parameters:node_name (String) – node name to match.
Return type:Returns an instance of axl.Node or None if no node was found.
child_called(node_name)

Allows to get the first node child, but with the provide name.

Parameters:node_name (String) – node name to match.
Return type:Returns an instance of axl.Node or None if no node was found.
find_called(node_name)

Gets the xml child node called as provided. The child is looked up in all childs found starting the parent node.

Parameters:node_name (String) – node name to match.
Return type:Returns an instance of axl.Node or None if no node was found.
nth_called(position)

Allows to get a reference to the child node located at the same level at the nth position.

Parameters:position (Integer) – node position.
Return type:Returns an instance of axl.Node or None if no node was found.
has_attr(attr_name[, attr_value])

Allows to check if the provided node has the given attribute.

Parameters:
  • attr_name (String) – the attribute name to check.
  • attr_value (String) – Optional the attribute value to check. If provided the method check if the node has an attribute with the provided value.
Return type:

Returns the presence of the provided attribute on the given node, and optionall checking if that attribute has a particular value.

attr(attr_name[, value])

Allows to get the value associated to the attribute (attr_name) or to configure the provided value if two arguments are provided.

Parameters:
  • attr_name (String) – the attribute name to get its value.
  • value (String) – If provided, allows to configure the value on the attribute (attr_name).
Return type:

Returns a string if only one parameter is provided representing the attribute value or None if attribute and value are provided.

attr_trans(attr_name)

Gets the attribute content for the provided attribute name, at the provided node, but translating entity references found.

Parameters:attr_name (String) – the attribute name to get its value.
Return type:Returns a string or None representing the attribute value.
set_child(node)

Allows to configure a new child node.

Parameters:node (axl.Node) – the new child node to configure.
set_child_after(node)

Allows to configure a new child node placing it after the calling node inside the same level. Both nodes will share parent node. Node must be not attached to a document. See deattach() to disconnect a node from a document or create a new node (axl.Node).

Parameters:node (axl.Node) – the new child node to configure.
attr_cursor_new()

Creates a new axl.AttrCursor instance which is used to perform efficient node attribute iteration. See axl_node_attr_cursor_new.

Parameters:node (axl.Node) – the new child node to configure.
remove([dealloc=True])

Allows to remove the node from its current document. By default the internal node is deallocated.

Parameters:node (axl.Node) – the new node to be removed from current holding document
replace([dealloc=True])

Allows to remove the node from its current document. By default the internal node is deallocated.

Parameters:node (axl.Node) – the new node to be removed from current holding document
deattach()

Allows to disconnect the node from its current document.

set_empty()

Allows to clear all content set inside a particular node.

name

(Read only attribute) (String) Allows to get the node name.

first_child

(Read only attribute) (axl.Node) Allows to get first node child.

next

(Read only attribute) (axl.Node) Allows to get next node.

previous

(Read only attribute) (axl.Node) Allows to get previous node.

parent

(Read only attribute) (axl.Node) Allows to get parent node.

content

(Read/Write attribute) (axl.Node) Allows to get/set the node content. See axl_node_get_content and axl_node_set_content from C API. The attribute detects on write operations if the content to be configured is not supported directly without replacing &, <, ‘, >, ”, and ;. In such case, Axl API translate the content (replacing those values by &amp;, &lt;, etc...).

The attribute returns a tuple with (content, size).

trans

(Read only attribute) (axl.Node) Allows to get content stored on a node translating known entity references: &amp;, &lt;, etc..

The attribute returns a tuple with (content, size).

doc

(Read only attribute) (axl.Doc) Allows to get the document that holds the node.