logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

r29202 - lxml/trunk/doc: msg#00202

Subject: r29202 - lxml/trunk/doc
Author: scoder
Date: Fri Jun 23 11:09:36 2006
New Revision: 29202

Modified:
   lxml/trunk/doc/api.txt
Log:
api.txt: el.iterancestors() and el.iterdescendants()

Modified: lxml/trunk/doc/api.txt
==============================================================================
--- lxml/trunk/doc/api.txt      (original)
+++ lxml/trunk/doc/api.txt      Fri Jun 23 11:09:36 2006
@@ -53,6 +53,7 @@
   >>> b = etree.SubElement(root, "b")
   >>> c = etree.SubElement(root, "c")
   >>> d = etree.SubElement(root, "d")
+  >>> e = etree.SubElement(d,    "e")
   >>> b.getparent() == root
   True
   >>> print b.getnext().tag
@@ -60,12 +61,17 @@
   >>> print c.getprevious().tag
   b
 
-You can also iterate over the siblings of an element::
+You can also iterate over the siblings, ancestors and descendants of an
+element, as defined by the respective XPath axes::
 
   >>> [ el.tag for el in a.itersiblings() ]
   ['b', 'c', 'd']
   >>> [ el.tag for el in c.itersiblings(preceding=True) ]
   ['b', 'a']
+  >>> [ el.tag for el in e.iterancestors() ]
+  ['d', 'root']
+  >>> [ el.tag for el in root.iterdescendants() ]
+  ['a', 'b', 'c', 'd', 'e']
 
 Elements always live within a document context in lxml.  This implies that
 there is also a notion of an absolute document root.  You can retrieve an
@@ -82,7 +88,7 @@
   >>> print tree.getroot().tag
   d
   >>> print etree.tostring(tree)
-  <d/>
+  <d><e/></d>
 
 All operations that you run on such an ElementTree (like XPath, XSLT, etc.)
 will understand the explicitly chosen root as root node of a document.  They


<Prev in Thread] Current Thread [Next in Thread>