summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjortel <devnull@localhost>2010-04-01 15:53:57 +0000
committerjortel <devnull@localhost>2010-04-01 15:53:57 +0000
commit82a9d5e19422b233461fb035473c21c42da8ded2 (patch)
tree5034341ca0dfdfddc28398e75d58dfcc48cee70a
parent72b7006b0e347e62ba32094cf8012e8860663612 (diff)
downloadsuds-82a9d5e19422b233461fb035473c21c42da8ded2.tar.gz
Add proper iterator for Element.
-rw-r--r--suds/sax/element.py35
-rw-r--r--suds/umx/core.py2
2 files changed, 36 insertions, 1 deletions
diff --git a/suds/sax/element.py b/suds/sax/element.py
index ca44801..0a015f1 100644
--- a/suds/sax/element.py
+++ b/suds/sax/element.py
@@ -923,6 +923,41 @@ class Element:
def __unicode__(self):
return self.str()
+
+ def __iter__(self):
+ return NodeIterator(self)
+
+
+class NodeIterator:
+ """
+ The L{Element} child node iterator.
+ @ivar pos: The current position
+ @type pos: int
+ @ivar children: A list of a child nodes.
+ @type children: [L{Element},..]
+ """
+
+ def __init__(self, parent):
+ """
+ @param parent: An element to iterate.
+ @type parent: L{Element}
+ """
+ self.pos = 0
+ self.children = parent.children
+
+ def next(self):
+ """
+ Get the next child.
+ @return: The next child.
+ @rtype: L{Element}
+ @raise StopIterator: At the end.
+ """
+ try:
+ child = self.children[self.pos]
+ self.pos += 1
+ return child
+ except:
+ raise StopIteration()
class PrefixNormalizer:
diff --git a/suds/umx/core.py b/suds/umx/core.py
index 7fb4ac4..07d33c4 100644
--- a/suds/umx/core.py
+++ b/suds/umx/core.py
@@ -135,7 +135,7 @@ class Core:
@param content: The current content being unmarshalled.
@type content: L{Content}
"""
- for child in content.node.children:
+ for child in content.node:
cont = Content(child)
cval = self.append(cont)
key = reserved.get(child.name, child.name)