Project

General

Profile

« Previous | Next » 

Revision 305

xml_dom.py: Added NodeIter() and Node.__iter__()

View differences:

lib/xml_dom.py
22 22
def has_one_child(node):
23 23
    return node.firstChild != None and node.firstChild.nextSibling == None
24 24

  
25
class NodeIter:
26
    def __init__(self, node): self.child = node.firstChild
27
    
28
    def __iter__(self): return self
29
    
30
    def curr(self):
31
        if self.child != None: return self.child
32
        raise StopIteration
33
    
34
    def next(self):
35
        child = self.curr()
36
        self.child = self.child.nextSibling
37
        return child
38

  
25 39
def is_elem(node): return node.nodeType == Node.ELEMENT_NODE
26 40

  
27 41
class NodeElemIter:
......
132 146

  
133 147
minidom._write_data = lambda writer, data: writer.write(escape(data))
134 148

  
149
minidom.Node.__iter__ = lambda self: NodeIter(self)
150

  
135 151
minidom.Node.__str__ = lambda self: self.toxml()
136 152

  
137 153
def __Element_write_opening(self, writer, indent='', addindent='', newl=''):

Also available in: Unified diff