lxml.objectify.ObjectifiedElement
Package lxml :: Module objectify :: Class ObjectifiedElement
[hide private]
[frames] | no frames]

Class ObjectifiedElement

    object --+        
             |        
etree._Element --+    
                 |    
 etree.ElementBase --+
                     |
                    ObjectifiedElement
Known Subclasses:

Main XML Element class.

Element children are accessed as object attributes. Multiple children with the same name are available through a list index. Example:

>>> root = XML("<root><c1><c2>0</c2><c2>1</c2></c1></root>")
>>> second_c2 = root.c1.c2[1]
>>> print(second_c2.text)
1

Note that you cannot (and must not) instantiate this class or its subclasses.

Instance Methods [hide private]
 
__delattr__(...)
x.__delattr__('name') <==> del x.name
 
__delitem__(x, y)
del x[y]
 
__getattr__(...)
Return the (first) child with the given tag name. If no namespace is provided, the child will be looked up in the same one as self.
 
__getattribute__(...)
x.__getattribute__('name') <==> x.name
 
__getitem__(...)
Return a sibling, counting from the first child of the parent. The method behaves like both a dict and a sequence.
 
__iter__(...)
Iterate over self and all siblings with the same tag.
 
__len__(...)
Count self and siblings with the same tag.
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__reduce__(...)
helper for pickle
 
__setattr__(...)
Set the value of the (first) child with the given tag name. If no namespace is provided, the child will be looked up in the same one as self.
 
__setitem__(...)
Set the value of a sibling, counting from the first child of the parent. Implements key assignment, item assignment and slice assignment.
 
__str__(x)
str(x)
 
addattr(self, tag, value)
Add a child value to the element.
 
countchildren(self)
Return the number of children of this element, regardless of their name.
 
descendantpaths(self, prefix=None)
Returns a list of object path expressions for all descendants.
 
getchildren(self)
Returns a sequence of all direct children. The elements are returned in document order.

Inherited from etree.ElementBase: __init__

Inherited from etree._Element: __contains__, __copy__, __deepcopy__, __nonzero__, __repr__, __reversed__, addnext, addprevious, append, clear, cssselect, extend, find, findall, findtext, get, getiterator, getnext, getparent, getprevious, getroottree, index, insert, items, iter, iterancestors, iterchildren, iterdescendants, iterfind, itersiblings, itertext, keys, makeelement, remove, replace, set, values, xpath

Inherited from etree._Element (private): _init

Inherited from object: __format__, __hash__, __reduce_ex__, __sizeof__, __subclasshook__

Properties [hide private]
  text
Text before the first subelement. This is either a string or the value None, if there was no text.

Inherited from etree._Element: attrib, base, nsmap, prefix, sourceline, tag, tail

Inherited from object: __class__

Method Details [hide private]

__delattr__(...)

 
x.__delattr__('name') <==> del x.name
Overrides: object.__delattr__

__delitem__(x, y)
(Index deletion operator)

 
del x[y]
Overrides: etree._Element.__delitem__

__getattribute__(...)

 
x.__getattribute__('name') <==> x.name
Overrides: object.__getattribute__

__getitem__(...)
(Indexing operator)

 

Return a sibling, counting from the first child of the parent. The method behaves like both a dict and a sequence.

  • If argument is an integer, returns the sibling at that position.
  • If argument is a string, does the same as getattr(). This can be used to provide namespaces for element lookup, or to look up children with special names (text etc.).
  • If argument is a slice object, returns the matching slice.
Overrides: etree._Element.__getitem__

__iter__(...)

 
Iterate over self and all siblings with the same tag.
Overrides: etree._Element.__iter__

__len__(...)
(Length operator)

 
Count self and siblings with the same tag.
Overrides: etree._Element.__len__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__reduce__(...)

 
helper for pickle
Overrides: object.__reduce__
(inherited documentation)

__setattr__(...)

 
Set the value of the (first) child with the given tag name. If no namespace is provided, the child will be looked up in the same one as self.
Overrides: object.__setattr__

__setitem__(...)
(Index assignment operator)

 

Set the value of a sibling, counting from the first child of the parent. Implements key assignment, item assignment and slice assignment.

  • If argument is an integer, sets the sibling at that position.
  • If argument is a string, does the same as setattr(). This is used to provide namespaces for element lookup.
  • If argument is a sequence (list, tuple, etc.), assign the contained items to the siblings.
Overrides: etree._Element.__setitem__

__str__(x)
(Informal representation operator)

 
str(x)
Overrides: object.__str__

addattr(self, tag, value)

 

Add a child value to the element.

As opposed to append(), it sets a data value, not an element.

getchildren(self)

 
Returns a sequence of all direct children. The elements are returned in document order.
Overrides: etree._Element.getchildren