title: Editing all text in childNodes of XML file with Python
body: <p>I'm trying to edit the text inside of all of the tags named "Volume" in an XML file by multiplying that text by a number entered by the user. The text inside of the "Volume" tag will always be a number. My code works so far, but only on the first instance of the "Volume" text.</p>
  
  <p>Here's an example of the XML:</p>
  
  <pre><code>         &lt;blah&gt;
                  &lt;moreblah&gt; sometext &lt;/moreblah&gt; ;
                  &lt;blah2&gt;
                          &lt;blah3&gt; &lt;blah4&gt; 30 &lt;/blah4&gt; &lt;Volume&gt; 15 &lt;/Volume&gt; &lt;/blah3&gt;
                  &lt;/blah2&gt;
          &lt;/blah&gt;
  
           &lt;blah&gt;
                  &lt;moreblah&gt; sometext &lt;/moreblah&gt; ;
                  &lt;blah2&gt;
                          &lt;blah3&gt; &lt;blah4&gt; 30 &lt;/blah4&gt; &lt;Volume&gt; 25 &lt;/Volume&gt; &lt;/blah3&gt;
                  &lt;/blah2&gt;
          &lt;/blah&gt;
  </code></pre>
  
  <p>And here's my Python code:</p>
  
  <pre><code>#import modules
  import xml.dom.minidom
  from xml.dom.minidom import parse
  import os
  import fileinput
  
  #create a backup of original file
  new_file_name = 'blah.xml'
  old_file_name = new_file_name + "_old"
  os.rename(new_file_name, old_file_name)
  
  #find all instances of "Volume"
  doc = parse(old_file_name)
  volume = doc.getElementsByTagName('Volume')[0]
  child = volume.childNodes[0]
  txt = child.nodeValue
  
  #ask for percentage input
  print
  percentage = raw_input("Set Volume Percentage (1 - 100): ")
  if percentage.isdigit():
      if int(percentage) &lt;101 &gt;1:
          print 'Thank You'
  
          #append text of &lt;Volume&gt; tag
          child.nodeValue = str(int(float(txt) * (int(percentage)/100.0)))
  
          #persist changes to new file
          xml_file = open(new_file_name, "w")
          doc.writexml(xml_file)
          xml_file.close()
  
          #remove XML Declaration
          text = open("blah.xml", "r").read()
          text = text.replace('&lt;?xml version="1.0" ?&gt;', '')  
          open("blah.xml", "w").write(text)
  
  
      else:
  
          print
          print 'Please enter a number between 1 and 100.'
          print 
          print 'Try again.'
          print
          print 'Exiting.'
  
  
          xml_file = open(new_file_name, "w")
          doc.writexml(xml_file)
          xml_file.close()
  
          os.remove(old_file_name)
  </code></pre>
  
  <p>I know that in my code, I have "doc.getElementsByTagName('Volume')[0]" which denotes the first instance of the "Volume" tag, but I was just doing that as a test to see if it would work. So I'm aware that the code is working exactly as it should. But I'm wondering if anyone has any suggestions, or could tell me the easiest way to apply the user input percentage to <strong>all</strong> of the instances of the "Volume" tag.</p>
  
  <p>This is also my first attempt at Python, so if you see anything else that seems weird, please let me know.</p>
  
  <p>Thank you for your help!</p>