Fandom

How To Wiki

How to parse XML in python

1,795pages on
this wiki
Add New Page
Talk1 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.



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.

Also on Fandom

Random Wiki