1.1 --- a/libxml2dom/__init__.py Mon Mar 12 20:20:01 2007 +0000
1.2 +++ b/libxml2dom/__init__.py Mon Mar 12 20:20:18 2007 +0000
1.3 @@ -29,6 +29,7 @@
1.4 parseFile as Node_parseFile, \
1.5 toString as Node_toString, toStream as Node_toStream, \
1.6 toFile as Node_toFile
1.7 +import urllib # for parseURI in HTML mode
1.8
1.9 class Implementation(object):
1.10
1.11 @@ -345,10 +346,10 @@
1.12 Node_removeChild(self._node, tmp)
1.13
1.14 def getElementsByTagName(self, tagName):
1.15 - return self.xpath("//" + tagName)
1.16 + return self.xpath(".//" + tagName)
1.17
1.18 def getElementsByTagNameNS(self, namespaceURI, localName):
1.19 - return self.xpath("//ns:" + localName, namespaces={"ns" : namespaceURI})
1.20 + return self.xpath(".//ns:" + localName, namespaces={"ns" : namespaceURI})
1.21
1.22 def normalize(self):
1.23 text_nodes = []
1.24 @@ -540,16 +541,29 @@
1.25 is set to a true value, the content to be parsed will be treated as being
1.26 HTML rather than XML.
1.27
1.28 - The parseURI does not currently work with HTML. Use parse with a stream
1.29 - object instead. For example:
1.30 + XML documents are retrieved using libxml2's own network capabilities; HTML
1.31 + documents are retrieved using the urllib module provided by Python. To
1.32 + retrieve either kind of document using Python's own modules for this purpose
1.33 + (such as urllib), open a stream and pass it to the parse function:
1.34
1.35 - d = parse(urllib.urlopen("http://www.python.org"), html=1)
1.36 + f = urllib.urlopen(uri)
1.37 + try:
1.38 + doc = libxml2dom.parse(f, html)
1.39 + finally:
1.40 + f.close()
1.41
1.42 A document object is returned by this function.
1.43 """
1.44
1.45 - impl = impl or default_impl
1.46 - return Document(Node_parseURI(uri, html), impl)
1.47 + if html:
1.48 + f = urllib.urlopen(uri)
1.49 + try:
1.50 + return parse(f, html, impl)
1.51 + finally:
1.52 + f.close()
1.53 + else:
1.54 + impl = impl or default_impl
1.55 + return Document(Node_parseURI(uri, html), impl)
1.56
1.57 def toString(node, encoding=None, prettyprint=0):
1.58