Experiment: Inhalte aus SoSci-XML extrahieren
- CDATA ist kein Problem - Eingeschachtelte Elemene parsen - XML-unquoting
This commit is contained in:
parent
a26bd9f133
commit
0ddd39a576
3 changed files with 109 additions and 20 deletions
|
|
@ -77,7 +77,9 @@ NOTE: es ist mit den gegebenen Mitteln nicht möglich, das Tabellen-Styling zu s
|
|||
Verarbeitungs-Schema
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
[yellow-background]#(dies ist der Plan zur Implementierung)#:
|
||||
Fragebogen-Definitionen können mit der Mini-DOM-Library gelesen werden, das Word-Dokument mit python-docx.
|
||||
Fragebogen-Definitionen können mit https://docs.python.org/3/library/xml.etree.elementtree.html[Elementtree]
|
||||
aus der Python-Standard-Library gelesen werden, das Word-Dokument mit
|
||||
https://python-docx.readthedocs.io/en/latest/index.html[python-docx(Documentation)].
|
||||
Die Verarbeitung untergliedert sich in drei Phasen:
|
||||
|
||||
1. SoSci-Definitionen einlesen
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1684368494840" ID="ID_1680262238" MODIFIED="1684377529586" POSITION="right" TEXT="Vor-Analyse (Hermann)">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1684368494840" ID="ID_1680262238" MODIFIED="1684448582270" POSITION="right" TEXT="Vor-Analyse (Hermann)">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1684377232205" ID="ID_1958647529" MODIFIED="1684377240495" TEXT="Word-Dokument">
|
||||
<node COLOR="#435e98" CREATED="1684377241659" ID="ID_211996471" MODIFIED="1684438272776" TEXT="Analyse">
|
||||
<icon BUILTIN="info"/>
|
||||
|
|
@ -167,7 +167,7 @@
|
|||
</node>
|
||||
</node>
|
||||
<node CREATED="1684425093938" ID="ID_983214559" MODIFIED="1684425101437" TEXT="SoSci-XML">
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425106925" ID="ID_1986143984" MODIFIED="1684425619449" TEXT="Analyse">
|
||||
<node COLOR="#435e98" CREATED="1684425106925" ID="ID_1986143984" MODIFIED="1684448071529" TEXT="Analyse">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1684425112703" ID="ID_1200576100" MODIFIED="1684425122363" TEXT="folgt grundsätzlich dem Aufbau der Web-Oberfläche"/>
|
||||
<node CREATED="1684425125074" ID="ID_590581145" MODIFIED="1684425134221" TEXT="spezieller Twist">
|
||||
|
|
@ -178,13 +178,20 @@
|
|||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425545402" ID="ID_678326426" MODIFIED="1684425580894" TEXT="Experimente">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425550850" ID="ID_53111427" MODIFIED="1684425577526" TEXT="CDATA aus XML holen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1684425545402" ID="ID_678326426" MODIFIED="1684448051586" TEXT="Experimente">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1684425550850" ID="ID_53111427" MODIFIED="1684448039373" TEXT="CDATA aus XML holen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425555507" ID="ID_1704018761" MODIFIED="1684425576097" TEXT="unquote char-Content">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1684425555507" ID="ID_1704018761" MODIFIED="1684448041439" TEXT="unquote char-Content">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684448042131" ID="ID_1128616077" MODIFIED="1684448050607" TEXT="über alle Pages im Questionaire iterieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1684448052898" ID="ID_463103903" MODIFIED="1684448065709" TEXT="alles easy">
|
||||
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
|
||||
<icon BUILTIN="ksmiletris"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -236,7 +243,7 @@
|
|||
<node CREATED="1684368381438" ID="ID_536028682" MODIFIED="1684368562213" POSITION="left" TEXT="Word verstehen">
|
||||
<font NAME="SansSerif" SIZE="16"/>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1684371396181" ID="ID_1494643844" MODIFIED="1684371402030" TEXT="ein Wort-Dokument">
|
||||
<node CREATED="1684371396181" FOLDED="true" ID="ID_1494643844" MODIFIED="1684448318966" TEXT="ein Wort-Dokument....">
|
||||
<node CREATED="1684371402940" ID="ID_775127417" MODIFIED="1684371610767" TEXT="is a ZIP-compressed folder">
|
||||
<node CREATED="1684371633747" ID="ID_315178960" MODIFIED="1684371642943" TEXT="holds ressources"/>
|
||||
<node CREATED="1684371709763" ID="ID_703260300" MODIFIED="1684371713790" TEXT="+ metadata"/>
|
||||
|
|
@ -249,7 +256,8 @@
|
|||
<node CREATED="1684371734712" ID="ID_1561962743" MODIFIED="1684371745264" TEXT="holds metadata"/>
|
||||
<node CREATED="1684371745750" ID="ID_1039576961" MODIFIED="1684371749874" TEXT="+ actual content"/>
|
||||
</node>
|
||||
<node CREATED="1684371422890" ID="ID_546163362" MODIFIED="1684371752987" TEXT="actual Content">
|
||||
<node CREATED="1684371422890" FOLDED="true" ID="ID_546163362" MODIFIED="1684448225501" TEXT="actual Content">
|
||||
<icon BUILTIN="back"/>
|
||||
<node CREATED="1684371432720" ID="ID_1123773556" MODIFIED="1684371453578" TEXT="a sequence of Paragraphs"/>
|
||||
<node CREATED="1684372227175" ID="ID_821942243" MODIFIED="1684372243007" TEXT="(or other block-level elements)">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
|
|
@ -310,7 +318,12 @@
|
|||
<node CREATED="1684368386013" ID="ID_271244982" MODIFIED="1684368562213" POSITION="left" TEXT="Python verstehen">
|
||||
<font NAME="SansSerif" SIZE="16"/>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node COLOR="#435e98" CREATED="1684369795005" ID="ID_1730265194" MODIFIED="1684369882498">
|
||||
<node COLOR="#435e98" CREATED="1684369795005" ID="ID_1730265194" MODIFIED="1684448581378" TEXT="Libraries">
|
||||
<edge COLOR="#5856c4" STYLE="linear"/>
|
||||
<cloud COLOR="#ccd0eb"/>
|
||||
<font NAME="SansSerif" SIZE="16"/>
|
||||
<icon BUILTIN="info"/>
|
||||
<node COLOR="#435e98" CREATED="1684444895031" ID="ID_24582245" MODIFIED="1684444920548">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
|
|
@ -320,15 +333,66 @@
|
|||
Modul <b>python-doxc</b>
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<edge COLOR="#5856c4" STYLE="linear"/>
|
||||
<cloud COLOR="#ccd0eb"/>
|
||||
<font NAME="SansSerif" SIZE="14"/>
|
||||
</html>
|
||||
</richcontent>
|
||||
<node CREATED="1684369841851" ID="ID_82528903" MODIFIED="1684444929524" TEXT="Doku">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1684369841851" ID="ID_1686589099" MODIFIED="1684369845472" TEXT="Doku">
|
||||
<node CREATED="1684369895137" ID="ID_775368900" LINK="https://pypi.org/project/python-docx/" MODIFIED="1684369900089" TEXT="pypi.org"/>
|
||||
<node CREATED="1684369901112" ID="ID_1856977529" MODIFIED="1684369907713" TEXT="readthedoks"/>
|
||||
</node>
|
||||
<node CREATED="1684448124993" ID="ID_1207539182" MODIFIED="1684448134499" TEXT="Standardfälle">
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1684448136157" ID="ID_1685757847" MODIFIED="1684448149185" TEXT="document.add_paragraph(<text>, style=<stylename>)"/>
|
||||
<node CREATED="1684448160291" ID="ID_1014538985" LINK="#ID_1369606274" MODIFIED="1684448204907" TEXT="Stylenamen werden in sichtbare Form übersetzt"/>
|
||||
<node CREATED="1684448234489" ID="ID_746702681" MODIFIED="1684448273543" TEXT="paragraph.text (Read/Write)">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Beim Schreiben wird der bestehende Content verworfen und durch einen einzigen Run ersetzt, der den gegebenen Text ohne weitere Formatierungen enthält
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1684444938400" ID="ID_1803428220" MODIFIED="1684444952121">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Modul <b>elementtree</b>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<node CREATED="1684444953007" ID="ID_1528197614" LINK="https://docs.python.org/3/library/xml.etree.elementtree.html" MODIFIED="1684444976183" TEXT="Doku">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1684369895137" ID="ID_1453810450" LINK="https://pypi.org/project/python-docx/" MODIFIED="1684369900089" TEXT="pypi.org"/>
|
||||
<node CREATED="1684369901112" ID="ID_1354824178" MODIFIED="1684369907713" TEXT="readthedoks"/>
|
||||
</node>
|
||||
<node CREATED="1684445181761" ID="ID_51292475" MODIFIED="1684445193504" TEXT="CDATA-Inhalt wird direkt unterstützt">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node CREATED="1684445195526" ID="ID_838670695" MODIFIED="1684445219368" TEXT="unescape">
|
||||
<node CREATED="1684445240208" ID="ID_1228520062" LINK="https://stackoverflow.com/a/54788611" MODIFIED="1684445249673" TEXT="direkt per html.unescape"/>
|
||||
<node CREATED="1684445266182" ID="ID_40459638" MODIFIED="1684445290580">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<pre http-equiv="content-type" content="text/html; charset=utf-8" class="default s-code-block"><code class="hljs language-coffeescript">>>> from html import unescape
|
||||
>>> unescape('&quot;')
|
||||
'"'</code></pre>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
|||
23
sosci2word/experiment2.py
Executable file
23
sosci2word/experiment2.py
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/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'))
|
||||
Loading…
Reference in a new issue