![]() |
XML minidom... help
I have been programming in python off and on and I am trying to really sit down and get more proficient in it this summer.
Right now I am trying to make a basic program for reading, modifying and writing data with an XML file. I am using minidom and I and here is the problem I am running into. Say I have a game inventory or something like this: :
<Inv>I want to return the Name section of Shield. If I use a function like "getElementsByTagName" then it will return a list containing the contents of all Name sections. How do I explicitly tell minidom to get an element in... say this order Inv>Shield>Name? I tried setting it up so it loaded the elements in that order i.e I loaded Inv into a variable then I loaded Shield and finally Name. That works fine if the document is small, but obviously that's inefficient, and I cant save the file if I choose to modify an element. I'm sure there is something simple that I am forgetting or that I missed(there always seems to be in python). Can someone please steer me in the right direction. |
:
|
Well what you posted is essentially what I did do read data from an XML file. However my problem really is about modifying the file. Say I want to change the "Broad Sword" to "Short Sword" or add another element to my XML file. I could do it that way, but wouldn't the changes just take place to the code that was in the variable? How do I modify and save the document.
|
Well, say you have found the element you want via the approach demonstrated above, and assigned it to the variable "sword":
:
However, this isn't a very good way of doing things. A better way would be to have a "dump" and "load" method on each class: :
:
:
|
Ok I see, thank you very much for the informative post:)
|
| All times are GMT -5. The time now is 8:10 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC