• Log in or sign up for an account here: https://www.sythe.org/login

[Python] Using The XML Library.

  • Thread starter Thread starter thiefmn6092
  • Start date Start date
T

thiefmn6092

Guest
XML is very useful when it comes to using it as a database or anything similiar. I'll explain the easiest way to use it in Python here

Here is our sample XML file.
Code:
<Sample>
      <SomeTable>
            <Attack>1</Attack>
      </SomeTable>
</Sample>

1. Imports
Code:
from xml.dom import minidom

2. Loading the XML file.
Code:
xmldoc = minidom.parse('YourFile.xml')

The above code will open the file "YourFile.xml" into dom and hold it in memory.

3. Extracting data ( SIMPLEST )
Code:
attack = xmldoc.getElementsByTagName('Attack')[0].firstchild.data

4. Displaying the data ( SIMPLEST )
Code:
print attack
[/code]
 
Runescape Gamblingrunescape gambling
Back
Top