GenericWrapper Class

class base.GenericWrapper(xmlnode=None)

GenericWrapper wrappes an lxml.Element object. If xmlnode is None a new node with elementname TAG will be created.

All output nodes are wrapped into GenericWrapper or a subclass of it and also all input nodes.

All wrapping classes are stored by the register_class() function in a central register. The wrap() function searches by the tag attribute of the lxml.Element for the appropriate wrapping class, calls this class cls(xmlnode=element) and returns the resulting object.

Attributes

GenericWrapper.TAG(read)

Tag name of the wrapped XML element (like <text:p>) in Clark Notation. To get the Clark Notation of an element use the xmlns.CN() function.

GenericWrapper.xmlnode(read)

Reference to the lxml.Element object.

GenericWrapper.text(read/write)

Get/Set the lxml.Element.text content as str.

GenericWrapper.tail(read/write)

Get/Set the lxml.Element.tail content as str.

GenericWrapper.textlen(read)

Should return the length of the plaintext() result.

GenericWrapper.kind(read)

Get the class name as str. (eg. 'GenericWrapper' for this class)

Methods

GenericWrapper.__init__(xmlnode=None)
GenericWrapper.__iter__()

Iterate over all child nodes, yields wrapped XML nodes.

GenericWrapper.__len__()

Get count of child nodes.

GenericWrapper.__getitem__(index)
Parameters:index (int) – numeric index

Get wrapped XML child-node at position index.

GenericWrapper.__setitem__(index, element)
Parameters:
  • index (int) – numeric index
  • element (GenericWrapper) – wrapped XML node

Set child at position index to element.

GenericWrapper.__delitem__(index)
Parameters:index (int) – numeric index

Delete child at position index.

GenericWrapper.index(child)
Parameters:child (GenericWrapper) – wrapped XML node

Get numeric index of child as int.

Raises IndexError if child.xmlnode is not in self.xmlnode

GenericWrapper.insert(index, child)
Parameters:child (GenericWrapper) – wrapped XML node
GenericWrapper.get_child(index)
Parameters:index (int) – numeric index
Returns:wrapped XML node

Get wrapped XML node at position index.

GenericWrapper.set_child(index, element)
Parameters:
  • index (int) – numeric index
  • element (GenericWrapper) – wrapped XML node
GenericWrapper.del_child(index)
Parameters:index (int) – numeric index

Remove XML node at position index.

GenericWrapper.findall(tag)
Parameters:tag (str) – tag name in Clark Notation

Find all subelements by xml-tag (in Clark Notation).

GenericWrapper.get_attr(key, default=None)
Parameters:key (str) – keyname

Get attribute key of wrapped XML node, or default if key doesn’t exist.

GenericWrapper.set_attr(key, value)
Parameters:
  • key (str) – keyname
  • value (str) – value

Set attribute key of the wrapped XML node to value.

GenericWrapper.append(child)
Parameters:child (GenericWrapper) – append wrapped XML node

Append child as last child into the wrapped XML node.

GenericWrapper.insert_before(target, child)
Parameters:
  • target (GenericWrapper) – target node
  • child (GenericWrapper) – new node

Insert child before the target node target.

GenericWrapper.remove(child)
Parameters:child (GenericWrapper) – wrapped XML node

Remove child from node.

GenericWrapper.clear()

Clear node content (text, tail, attributes) and remove all children.

GenericWrapper.plaintext()

Returns the plaintext representation of the node.

Table Of Contents

Previous topic

XML Namespace Helper Tools

Next topic

Document Classes

This Page