Wikia

How To Wiki

How to parse XML in python

Talk1
1,788pages on
this wiki



Python have a XML modules to parse trees. You can use it to store and receive data from text files (.xml extension is not required). There is many editors to edit trees (See Links below to find one).

ElementTreeEdit

Loading filesEdit

#importing module as ET for easiest writing

from xml.etree import ElementTree as ET

#parse file test.xml. In result we get ET.ElementTree object
document=ET.parse("test.xml")

#print the main node name
mainnode.document.getroot()
print mainnode.tag

test.xml

<mainnode>
    <node>
        <textnode>this is a text inside a node.</textnode>
    </node>
</mainnode>

See:Edit

Editors to edit xml treeEdit


From HowTo Wiki, a Wikia wiki.

Around Wikia's network

Random Wiki