XML parsing from file to text PYTHON



I need to get text values from XML files in Python.


My actual XML file is:



<?xml version="1.0"?>
<data>
<command>first</command>
<command>second</command>
<command>third</command>
</data>


I need read it from a file and then obtain an output like:



first
second
third


Im doing a little source like:



from xml.dom import minidom
doc = minidom.parse("C:\ciao.xml")
name = doc.getElementsByTagName("command")[0]
print(name.firstChild.data)


But i need get all commands and not just one by one


No comments:

Post a Comment