comparison emeraldtree/tree.py @ 66:048d2f8de762

Tree - Make Node writable
author Bastian Blank <bblank@thinkmo.de>
date Sun, 30 May 2010 17:28:19 +0200
parents d3fcc3556413
children a271e50bea43
comparison
equal deleted inserted replaced
65:d3fcc3556413 66:048d2f8de762
75 class Node(object): 75 class Node(object):
76 """ 76 """
77 Node class. 77 Node class.
78 """ 78 """
79 79
80 def write(self, write, encoding=None, namespaces={}, method=None):
81 if not method or method == "xml":
82 Writer = XMLWriter
83 elif method == "html":
84 Writer = HTMLWriter
85 else:
86 Writer = TextWriter
87
88 Writer(encoding, namespaces).write(write, self)
89
90
80 ## 91 ##
81 # Element class. This class defines the Element interface, and 92 # Element class. This class defines the Element interface, and
82 # provides a reference implementation of this interface. 93 # provides a reference implementation of this interface.
83 # <p> 94 # <p>
84 # The element name, attribute names, and attribute values can be 95 # The element name, attribute names, and attribute values can be
367 if isinstance(e, Element): 378 if isinstance(e, Element):
368 for s in e.itertext(): 379 for s in e.itertext():
369 yield s 380 yield s
370 elif isinstance(e, basestring): 381 elif isinstance(e, basestring):
371 yield e 382 yield e
372
373 def write(self, write, encoding=None, namespaces={}, method=None):
374 if not method or method == "xml":
375 Writer = XMLWriter
376 elif method == "html":
377 Writer = HTMLWriter
378 else:
379 Writer = TextWriter
380
381 Writer(encoding, namespaces).write(write, self)
382 383
383 384
384 ## 385 ##
385 # Subelement factory. This function creates an element instance, and 386 # Subelement factory. This function creates an element instance, and
386 # appends it to an existing element. 387 # appends it to an existing element.