# HG changeset patch # User paulb # Date 1128940203 0 # Node ID 9aa2eae5a9210ce253f8d8922b1d6884394ed9eb # Parent e94fda5e2d3e306f83a335d08ec6b037a5b41ab4 [project @ 2005-10-10 10:29:58 by paulb] Added prettyprinting support. diff -r e94fda5e2d3e -r 9aa2eae5a921 README.txt --- a/README.txt Sat Sep 10 21:59:28 2005 +0000 +++ b/README.txt Mon Oct 10 10:30:03 2005 +0000 @@ -50,6 +50,7 @@ * Moved libxml2macro script to the tools directory. * Added getElementsByTagNameNS. * Added HTML parsing support. + * Added prettyprinting support. * Fixed parseURI. * Introduced better testing for Unicode objects, especially since things like rdflib like to subclass the unicode type, and it might be more diff -r e94fda5e2d3e -r 9aa2eae5a921 libxml2dom/__init__.py --- a/libxml2dom/__init__.py Sat Sep 10 21:59:28 2005 +0000 +++ b/libxml2dom/__init__.py Mon Oct 10 10:30:03 2005 +0000 @@ -299,14 +299,14 @@ # Convenience methods. - def toString(self, encoding=None): - return toString(self, encoding) + def toString(self, encoding=None, prettyprint=0): + return toString(self, encoding, prettyprint) - def toStream(self, stream, encoding=None): - toStream(self, stream, encoding) + def toStream(self, stream, encoding=None, prettyprint=0): + toStream(self, stream, encoding, prettyprint) - def toFile(self, f, encoding=None): - toFile(self, f, encoding) + def toFile(self, f, encoding=None, prettyprint=0): + toFile(self, f, encoding, prettyprint) # Attribute nodes. @@ -413,35 +413,41 @@ return Document(Node_parseURI(uri, html)) -def toString(node, encoding=None): +def toString(node, encoding=None, prettyprint=0): """ Return a string containing the serialised form of the given 'node' and its children. The optional 'encoding' can be used to override the default - character encoding used in the serialisation. + character encoding used in the serialisation. The optional 'prettyprint' + indicates whether the serialised form is prettyprinted or not (the default + setting). """ - return Node_toString(node.as_native_node(), encoding) + return Node_toString(node.as_native_node(), encoding, prettyprint) -def toStream(node, stream, encoding=None): +def toStream(node, stream, encoding=None, prettyprint=0): """ Write the serialised form of the given 'node' and its children to the given 'stream'. The optional 'encoding' can be used to override the default - character encoding used in the serialisation. + character encoding used in the serialisation. The optional 'prettyprint' + indicates whether the serialised form is prettyprinted or not (the default + setting). """ - Node_toStream(node.as_native_node(), stream, encoding) + Node_toStream(node.as_native_node(), stream, encoding, prettyprint) -def toFile(node, filename, encoding=None): +def toFile(node, filename, encoding=None, prettyprint=0): """ Write the serialised form of the given 'node' and its children to a file having the given 'filename'. The optional 'encoding' can be used to override - the default character encoding used in the serialisation. + the default character encoding used in the serialisation. The optional + 'prettyprint' indicates whether the serialised form is prettyprinted or not + (the default setting). """ - Node_toFile(node.as_native_node(), filename, encoding) + Node_toFile(node.as_native_node(), filename, encoding, prettyprint) def adoptNodes(nodes): diff -r e94fda5e2d3e -r 9aa2eae5a921 libxml2dom/macrolib/macrolib.py --- a/libxml2dom/macrolib/macrolib.py Sat Sep 10 21:59:28 2005 +0000 +++ b/libxml2dom/macrolib/macrolib.py Mon Oct 10 10:30:03 2005 +0000 @@ -380,14 +380,14 @@ else: raise NotSupportedError, "parseURI does not yet support HTML" -def toString(node, encoding=None): - return libxml2mod.serializeNode(node, encoding, 0) +def toString(node, encoding=None, prettyprint=0): + return libxml2mod.serializeNode(node, encoding, prettyprint) -def toStream(node, stream, encoding=None): - stream.write(toString(node, encoding)) +def toStream(node, stream, encoding=None, prettyprint=0): + stream.write(toString(node, encoding, prettyprint)) -def toFile(node, f, encoding=None): - libxml2mod.saveNodeTo(node, f, encoding, 0) +def toFile(node, f, encoding=None, prettyprint=0): + libxml2mod.saveNodeTo(node, f, encoding, prettyprint) # libxml2mod constants.