1.1 --- a/libxml2dom/__init__.py Wed Aug 03 22:21:15 2005 +0000
1.2 +++ b/libxml2dom/__init__.py Wed Aug 03 22:21:19 2005 +0000
1.3 @@ -361,31 +361,96 @@
1.4 return Document(Node_createDocument(namespaceURI, localName, doctype))
1.5
1.6 def parse(stream_or_string, html=0):
1.7 +
1.8 + """
1.9 + Parse the given 'stream_or_string', where the supplied object can either be
1.10 + a stream (such as a file or stream object), or a string (containing the text
1.11 + of a document). If the optional 'html' parameter is set to a true value, the
1.12 + content to be parsed will be treated as being HTML rather than XML.
1.13 +
1.14 + A document object is returned by this function.
1.15 + """
1.16 +
1.17 if hasattr(stream_or_string, "read"):
1.18 stream = stream_or_string
1.19 return parseString(stream.read(), html)
1.20 else:
1.21 return parseFile(stream_or_string, html)
1.22
1.23 -def parseFile(s, html=0):
1.24 - return Document(Node_parseFile(s, html))
1.25 +def parseFile(filename, html=0):
1.26 +
1.27 + """
1.28 + Parse the file having the given 'filename'. If the optional 'html' parameter
1.29 + is set to a true value, the content to be parsed will be treated as being
1.30 + HTML rather than XML.
1.31 +
1.32 + A document object is returned by this function.
1.33 + """
1.34 +
1.35 + return Document(Node_parseFile(filename, html))
1.36
1.37 def parseString(s, html=0):
1.38 +
1.39 + """
1.40 + Parse the content of the given string 's'. If the optional 'html' parameter
1.41 + is set to a true value, the content to be parsed will be treated as being
1.42 + HTML rather than XML.
1.43 +
1.44 + A document object is returned by this function.
1.45 + """
1.46 +
1.47 return Document(Node_parseString(s, html))
1.48
1.49 def parseURI(uri, html=0):
1.50 +
1.51 + """
1.52 + Parse the content found at the given 'uri'. If the optional 'html' parameter
1.53 + is set to a true value, the content to be parsed will be treated as being
1.54 + HTML rather than XML.
1.55 +
1.56 + A document object is returned by this function.
1.57 + """
1.58 +
1.59 return Document(Node_parseURI(uri, html))
1.60
1.61 def toString(node, encoding=None):
1.62 +
1.63 + """
1.64 + Return a string containing the serialised form of the given 'node' and its
1.65 + children. The optional 'encoding' can be used to override the default
1.66 + character encoding used in the serialisation.
1.67 + """
1.68 +
1.69 return Node_toString(node.as_native_node(), encoding)
1.70
1.71 def toStream(node, stream, encoding=None):
1.72 +
1.73 + """
1.74 + Write the serialised form of the given 'node' and its children to the given
1.75 + 'stream'. The optional 'encoding' can be used to override the default
1.76 + character encoding used in the serialisation.
1.77 + """
1.78 +
1.79 Node_toStream(node.as_native_node(), stream, encoding)
1.80
1.81 -def toFile(node, f, encoding=None):
1.82 - Node_toFile(node.as_native_node(), f, encoding)
1.83 +def toFile(node, filename, encoding=None):
1.84 +
1.85 + """
1.86 + Write the serialised form of the given 'node' and its children to a file
1.87 + having the given 'filename'. The optional 'encoding' can be used to override
1.88 + the default character encoding used in the serialisation.
1.89 + """
1.90 +
1.91 + Node_toFile(node.as_native_node(), filename, encoding)
1.92
1.93 def adoptNodes(nodes):
1.94 +
1.95 + """
1.96 + A special utility method which adopts the given low-level 'nodes' and which
1.97 + returns a list of high-level equivalents. This is currently experimental and
1.98 + should not be casually used.
1.99 + """
1.100 +
1.101 if len(nodes) == 0:
1.102 return []
1.103 doc = Document(libxml2mod.doc(nodes[0]))