Author: dmeyer
Date: Mon Feb 13 17:45:00 2006
New Revision: 1174

Modified:
   trunk/base/src/base/libxml2.py
   trunk/base/test/libxml2.py

Log:
update iterator to go thru all nodes

Modified: trunk/base/src/base/libxml2.py
==============================================================================
--- trunk/base/src/base/libxml2.py      (original)
+++ trunk/base/src/base/libxml2.py      Mon Feb 13 17:45:00 2006
@@ -128,6 +128,9 @@
             return None
         return Node(_obj=ret)
 
+    def __iter__(self):
+        return NodeIterator(self)
+    
     parent = property(get_parent, None, None, "Parent node")
     children = property(get_children, None, None, "All not text children 
nodes")
 
@@ -221,6 +224,21 @@
         
 
 
+class NodeIterator:
+    def __init__(self, node):
+        self.node = node.get_first()
+
+    def __iter__(self):
+        return self
+
+    def next(self):
+        if not self.node:
+            raise StopIteration
+        ret = self.node
+        self.node = self.node.next
+        return ret
+
+
 class Document(Node):
     def __init__(self, filename=None, root=None):
         if root:

Modified: trunk/base/test/libxml2.py
==============================================================================
--- trunk/base/test/libxml2.py  (original)
+++ trunk/base/test/libxml2.py  Mon Feb 13 17:45:00 2006
@@ -5,12 +5,21 @@
 
 for c in x.children:
     print c.name, c.type, c.parent.name
+print
+
+for c in x:
+    print c.name, c.type
+print
+
+for c in x.children:
     if c.name == 'movie':
         print 'title is', c.getattr('title')
         for y in c.get_child('info').children:
             print y.name, y.content, type(y.content)
+print
         
 
+
 x = libxml2.Document(root='freevo')
 
 c = libxml2.Node('foo')


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to