On Oct 12, 11:19 pm, cakebread <[EMAIL PROTECTED]> wrote:
> I'm having problems parsing a file:
>
> >>> tree = ElementTree.fromstring("""<html
> >>> xmlns="http://www.w3.org/1999/xhtml"
> >>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> >>> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
> >>> xmlns:dc="http://purl.org/dc/elements/1.1/"
> >>> xmlns:foaf="http://xmlns.com/foaf/0.1/"
> >>> xmlns:doap="http://usefulinc.com/ns/doap#">
>
> <body>Hello world</body>
> </html>""")
>
> >>> print tree.find('body')
>
> None
>
> The above works fine with the first element being a simple <html>, but
> not when I have all the xmlns's.
>
> Thanks,
> Rob
You have to prefix the element name with its namespace. The following
will work
>>> tree.find('{http://www.w3.org/1999/xhtml}body')
<Element {http://www.w3.org/1999/xhtml}body at 779d28>
(Python 2.5, OS X 10.4.10)
--
http://mail.python.org/mailman/listinfo/python-list