I want to parse a xml file and save it as a txt file.
My XML-File looks like follows:
I am just interested in the attribute
type inside the class ATTRIBUTE. I want just to display the values
Demonstration and
Portfolio in a text file
<ADOXML adoversion="Version 5.1" username="Admin" database="adoxxdb" time="10:39" date="21.10.2019" version="3.1">
<MODELS>
<MODEL version="" applib="ADOxx 1.5 Dynamic Experimentation Library" libtype="bp" modeltype="Ressource Model" name="Ressource Model - new" id="mod.47204">
<MODELATTRIBUTES>
<INSTANCE name="Collection of written documents-49041" id="obj.49041" class="Collection of written documents">
<ATTRIBUTE name="Position" type="STRING">NODE x:7cm y:1.5cm index:1</ATTRIBUTE>
<ATTRIBUTE name="External tool coupling" type="STRING"/>
<ATTRIBUTE name="Comment" type="STRING"/>
<ATTRIBUTE name="Description" type="STRING"/>
<ATTRIBUTE name="Referenced Document" type="PROGRAMCALL">ITEM "" param:""</ATTRIBUTE>
<ATTRIBUTE name="Display file name" type="INTEGER">0</ATTRIBUTE>
<ATTRIBUTE name="Type of written documents" type="ENUMERATIONLIST">Demonstration;Portfolio</ATTRIBUTE>
</INSTANCE>
</MODEL>
</MODELS>
</ADOXML>
The output should just look like:
Klassen:
Demonstration
Portfolio
My code looks like follows:
What I have tried:
import xml.etree.ElementTree as ET
tree=ET.parse(r"C:\Users\benni\Google Drive\MASTER\Masterarbeit\Coden\Resource.xml")
with open(r"C:\Users\benni\Google Drive\MASTER\Masterarbeit\Coden\Output88.txt", "w")as f:
f.write("Class\n")
for instance in tree.findall(".//ATTRIBUTE"):
f.write(f"{instance.get('type')}\n")
However, I do not get the results I wanted. I just get the attribute ENUMERATIONLIST, but I want the values of this.