22 lines
570 B
Python
Executable file
22 lines
570 B
Python
Executable file
import xml.etree.ElementTree as ET
|
|
import json
|
|
|
|
tree = ET.parse('small.xml')
|
|
root = tree.getroot()
|
|
res = []
|
|
|
|
for wordEl in root:
|
|
alreadyAdd = False
|
|
for wordChild in wordEl:
|
|
if wordChild.tag == "lexeme" and not alreadyAdd:
|
|
word = wordEl.attrib.get("form")
|
|
wordType = wordChild.attrib.get("pos")
|
|
if word is not None and wordType is not None:
|
|
res.append({
|
|
"word": word,
|
|
"type": wordType
|
|
})
|
|
alreadyAdd = True
|
|
|
|
|
|
print(json.dumps(res))
|