Problem parsing namespaces with xml.dom.minidom

Paul Prescod paul at prescod.net
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='http://www.mcs.vuw.ac.nz/renata/xte'>
    <xte:creator>alias</xte:creator>
    <xte:date>Thu Jan 30 15:06:06 NZDT 2003</xte:date>
    <xte:object objectid="object1">
      Nothing
    </xte:object>
</xte:xte>
'''

# 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(
     'http://www.mcs.vuw.ac.nz/renata/xte',"object",
)
print '1: ' + str(object_el1)
print '2: ' + str(object_el2)




More information about the Python-list mailing list