from xml.dom import minidom
dict[1] = "country"
xmldoc = minidom.parse('TestStep.xml')
itemlist = xmldoc.getElementsByTagName('TestStepBody')
print len(itemlist)
print itemlist[0].attributes['Author'].value
itemlist[0].setAttribute("Author",dict[1]);
for s in itemlist :
print s.attributes['Author'].value

dict[1] value will be changing dynamically, So i need to dynamically change the attribute value of the Author in python. I this possible? if so Can any one help me in this.

I don't really use the xml module, and it would really help if you could format your code. But this is what I found:

s = '<foo name="test"><foobar name="original"></foobar></foo>'
d = minidom.parseString(s)
elems = d.getElementsByTagName('foobar')
elems[0].setAttribute('name', 'changed!')
print(d.toprettyxml(indent='    '))

Output:

<?xml version="1.0" ?>
<foo name="test">
    <foobar name="changed!"/>
</foo>

The element is changed. Instead of print, just write it to a file. Hint:

with open('myfile.new.xml', 'w') as f:
    d.writexml(f, addindent='    ', newl='\n')

Or:

with open('myfile.new.xml', 'w') as f:
    f.write(d.toprettyxml(indent='    '))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.