Skip to content

Commit 116db7a

Browse files
author
Arzaroth Lekva
committed
dictnode iterator
1 parent c3624bf commit 116db7a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rapidxml/rapidxml.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
import _rapidxml
1010

11+
class DictNodeIterator(object):
12+
def __init__(self, iterable):
13+
self._iter = iterable
14+
15+
def __next__(self):
16+
return self.next()
17+
18+
def next(self):
19+
return DictNode().copy(next(self._iter))
20+
21+
def __iter__(self):
22+
return self
23+
24+
1125
class DictNode(_rapidxml.Node):
1226
def __init__(self, attribute_prefix='@', cdata_key='#text'):
1327
_rapidxml.Node.__init__(self)
@@ -59,6 +73,10 @@ def __contains__(self, name):
5973
return False
6074
return True
6175

76+
def __iter__(self):
77+
return DictNodeIterator(self.children)
78+
79+
6280
class RapidXml(DictNode, _rapidxml.Document):
6381
def __init__(self,
6482
text="",

0 commit comments

Comments
 (0)