[Tutor] getAttribute

Kent Johnson kent37 at tds.net
Fri Mar 31 15:14:53 CEST 2006


kakada wrote:
> Hello all,
> 
> Could anyone help me by giving example of getAttribute
> 
> xmldata = ziparchive.read("content.xml")
> xmldoc = minidom.parseString(xmldata)
> officeNode = xmldoc.getElementsByTagName('office:text')
> 
> I have another function:
> def go_thru (nodelist):
>     for x in range(nodelist.length):
>         node = nodelist[x]
>         i = 0
>         print node.getAttribute('text:style-name')
> 
> go_thru(officeNode) #Calling function
> 
> I always get error message: AttributeError: Text instance has no
> attribute 'getAttribute'
> Could anyone give an explanation?

I think it should be node.attributes['text:style-name'].nodeValue.

You might want to look at ElementTree, it is a more Pythonic XML library.

Kent



More information about the Tutor mailing list