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__(self)
Iterate over self and all siblings with the same tag.
 
__len__(x)
len(x)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
 
__setitem__(x, i, y)
x[i]=y
 
__str__(...)
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.
 
find(self, path)
Finds the first matching subelement, by tag name or path.
 
findall(self, path)
Finds all matching subelements, by tag name or path.
 
findtext(self, path, default=None)
Finds text for the first matching subelement, by tag name or path.
 
getchildren(self)
Returns a sequence of all direct children. The elements are returned in document order.
 
iterfind(self, path)
Iterates over all matching subelements, by tag name or path.

Inherited from etree.ElementBase: __init__

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

Inherited from etree._Element (private): _init

Inherited from object: __format__, __hash__, __reduce__, __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__(self)

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

__len__(x)
(Length operator)

 
len(x)
Overrides: etree._Element.__len__

__new__(T, S, ...)

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

__setattr__(...)

 
x.__setattr__('name', value) <==> x.name = value
Overrides: object.__setattr__

__setitem__(x, i, y)
(Index assignment operator)

 
x[i]=y
Overrides: etree._Element.__setitem__

__str__(...)
(Informal representation operator)

 
str(x)
Overrides: object.__str__
(inherited documentation)

addattr(self, tag, value)

 

Add a child value to the element.

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

find(self, path)

 
Finds the first matching subelement, by tag name or path.
Overrides: etree._Element.find

findall(self, path)

 
Finds all matching subelements, by tag name or path.
Overrides: etree._Element.findall

findtext(self, path, default=None)

 
Finds text for the first matching subelement, by tag name or path.
Overrides: etree._Element.findtext

getchildren(self)

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

iterfind(self, path)

 
Iterates over all matching subelements, by tag name or path.
Overrides: etree._Element.iterfind