[Tutor] Writing to XML file with minidom
Johan Geldenhuys
johan at accesstel.co.za
Tue Aug 30 12:24:49 CEST 2005
Thanks for he help, so far.
I am still having some questions on writing my new string back to the
xml file after I found what I was looking for and changed it.
Extracts:
xmlDocument = minidom.parse(file_name) # open existing file for parsing
main = xmlDocument.getElementsByTagName('Config')
main.getElementsByTagName('Connection')
configSection = mainSection[0]
for node in configSection: #Here I get the NamedNodeMap info
password = node.getAttribute("password")
# Do stuff to the password and I have 'newPass'
node.removeAttribute('password') # I take out my old attribute
and it's value
node.setAttribute('password', newPass)
At this stage I have my new attribute and it's new value, but how do I
write that to my file in the same place?
I have to get a 'writer', how do I do this?
Do I have to write all the data back or can I just replace the pieces I
changed?
Thanks,
Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050830/6bd5d473/attachment.htm
-------------- next part --------------
An embedded message was scrubbed...
From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Writing to XML file with minidom
Date: Mon, 22 Aug 2005 10:57:36 -0700 (PDT)
Size: 3127
Url: http://mail.python.org/pipermail/tutor/attachments/20050830/6bd5d473/attachment.mht
More information about the Tutor
mailing list