wegen/sosci2word/experiment2.py
Ichthyostega 0ddd39a576 Experiment: Inhalte aus SoSci-XML extrahieren
- CDATA ist kein Problem
- Eingeschachtelte Elemene parsen
- XML-unquoting
2023-05-19 00:27:17 +02:00

23 lines
No EOL
592 B
Python
Executable file

#!/usr/bin/python3
from xml.etree import ElementTree
root = ElementTree.parse('ThesisFragebogen.2023-04-19.xml').getroot()
layout = root.find('surveyLayout').find('template')
print(layout.text)
quest = root.find('questionnaire').find('attributes.specific')
quest = next(a for a in quest.findall('attr') if a.get('id') == 'content')
print(quest.text)
questRoot = ElementTree.fromstring(quest.text)
for page in questRoot.findall('page'):
info = page.find('info')
if info != None:
print(info.text)
for quest in page.findall('question'):
print(quest.get('id'))