Problem parsing namespaces with xml.dom.minidom

Paul Prescod paul at
Tue Jan 18 06:46:24 EST 2005

You've reversed some function parameters. Here's a program that works 
fine (note that you don't need to set up a SAX parser):

from xml.dom import minidom
text = '''<?xml version="1.0" encoding="UTF-8"?>
<xte:xte xmlns:xte=''>
    <xte:date>Thu Jan 30 15:06:06 NZDT 2003</xte:date>
    <xte:object objectid="object1">

# Parse the string into a minidom
mydom = minidom.parseString(text)

# Look for some elements

# This one shouldn't return any (I think).
object_el1 = mydom.getElementsByTagName("xte:object")

# This one definitely should, at least for what I want.
object_el2 = mydom.getElementsByTagNameNS(
print '1: ' + str(object_el1)
print '2: ' + str(object_el2)

More information about the Python-list mailing list