Project

General

Profile

« Previous | Next » 

Revision 888

xml_dom.py: by_tag_name(): Iterate forwards over children unless last_only optimization turned on. Added Attr.__str__() and repr() for debug-printing Attrs.

View differences:

xml_dom.py
177 177
def by_tag_name(node, name, last_only=False):
178 178
    '''last_only optimization returns last matching node'''
179 179
    children = []
180
    for child in NodeElemReverseIter(node):
180
    if last_only: iter_ = NodeElemReverseIter(node)
181
    else: iter_ = NodeElemIter(node)
182
    for child in iter_:
181 183
        if child.tagName == name:
182 184
            children.append(child)
183 185
            if last_only: break
......
206 208
minidom.Node.__repr__ = __Node_str
207 209
minidom.Element.__repr__ = __Node_str
208 210

  
211
def __Attr_str(self): return self.name+'="'+escape(self.value)+'"'
212
minidom.Attr.__str__ = __Attr_str
213
minidom.Attr.__repr__ = __Attr_str
214

  
209 215
minidom.Node.pop = lambda self: self.removeChild(self.lastChild)
210 216

  
211 217
def __Node_clear(self):

Also available in: Unified diff