[Python] Using The XML Library.

Discussion in 'Web Programming' started by thiefmn6092, Jan 30, 2007.

[Python] Using The XML Library.
  1. Unread #1 - Jan 30, 2007 at 11:42 AM
  2. thiefmn6092
    Referrals:
    0

    thiefmn6092 Guest

    [Python] Using The XML Library.

    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]
     
< please help- ranking script | >

Users viewing this thread
1 guest


 
 
Adblock breaks this site