|
|
|
@ -5,7 +5,7 @@ from model.tags import export_tag
|
|
|
|
|
def export_to_xml(model):
|
|
|
|
|
xml_document = export_entry(model.entry)
|
|
|
|
|
serializer = __new__(XMLSerializer())
|
|
|
|
|
return serializer.serializeToString(xml_document);
|
|
|
|
|
return serializer.serializeToString(xml_document)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export_entry(entry):
|
|
|
|
@ -23,9 +23,14 @@ def export_entry(entry):
|
|
|
|
|
|
|
|
|
|
headword = doc.createElement("headword")
|
|
|
|
|
headword_lemma = doc.createElement("lemma")
|
|
|
|
|
|
|
|
|
|
# headword_lemma = entry.original_xml.querySelector("head headword lemma")
|
|
|
|
|
|
|
|
|
|
headword_lemma.textContent = entry.headword
|
|
|
|
|
if entry.headword_type is not None:
|
|
|
|
|
headword_lemma.setAttribute("type", entry.headword_type)
|
|
|
|
|
if entry.headword_audio is not None:
|
|
|
|
|
headword_lemma.setAttribute("audio", entry.headword_audio)
|
|
|
|
|
headword.appendChild(headword_lemma)
|
|
|
|
|
head.appendChild(headword)
|
|
|
|
|
|
|
|
|
@ -52,11 +57,18 @@ def export_entry(entry):
|
|
|
|
|
lexunit.appendChild(lexeme)
|
|
|
|
|
head.appendChild(lexunit)
|
|
|
|
|
|
|
|
|
|
# Example of keeping original xml and adding changes to it only
|
|
|
|
|
grammar_category = entry.original_xml.querySelector("head grammar category")
|
|
|
|
|
if grammar_category is None:
|
|
|
|
|
grammar = doc.createElement("grammar")
|
|
|
|
|
grammar_category = doc.createElement("category")
|
|
|
|
|
grammar_category.textContent = entry.grammar
|
|
|
|
|
grammar.appendChild(grammar_category)
|
|
|
|
|
head.appendChild(grammar)
|
|
|
|
|
entry.original_xml.querySelector("head").appendChild(grammar_category)
|
|
|
|
|
|
|
|
|
|
grammar_category.textContent = entry.grammar
|
|
|
|
|
|
|
|
|
|
head.appendChild(entry.original_xml.querySelector("head grammar"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(entry.measure) > 0:
|
|
|
|
|
measure_list = doc.createElement("measureList")
|
|
|
|
@ -125,7 +137,9 @@ def export_sense(doc, sense):
|
|
|
|
|
|
|
|
|
|
for example in sense.examples:
|
|
|
|
|
example_container = example.export(doc)
|
|
|
|
|
export_translation_list(doc, example, example_container)
|
|
|
|
|
translation_container_list = doc.createElement("translationContainerList")
|
|
|
|
|
export_translation_list(doc, example, translation_container_list)
|
|
|
|
|
example_container.appendChild(translation_container_list)
|
|
|
|
|
example_container_list.appendChild(example_container)
|
|
|
|
|
|
|
|
|
|
return sense_xml
|
|
|
|
@ -146,26 +160,27 @@ def export_translation(doc, translation):
|
|
|
|
|
actual_t.textContent = translation.translation
|
|
|
|
|
actual_t.setAttribute("targetLang", translation.targetLang)
|
|
|
|
|
|
|
|
|
|
if translation.audio:
|
|
|
|
|
actual_t.setAttribute("audio", translation.audio)
|
|
|
|
|
|
|
|
|
|
if translation.source:
|
|
|
|
|
actual_t.setAttribute("source", translation.source)
|
|
|
|
|
translation_xml.appendChild(actual_t)
|
|
|
|
|
|
|
|
|
|
explanationList = doc.createElement("explanationList")
|
|
|
|
|
|
|
|
|
|
for explanation in translation.explanationList:
|
|
|
|
|
el = doc.createElement("explanation")
|
|
|
|
|
el.textContent = explanation
|
|
|
|
|
explanationList.appendChild(el)
|
|
|
|
|
|
|
|
|
|
if len(translation.explanationList) > 0 :
|
|
|
|
|
explanationList = _export_explanation_list(doc, translation.explanationList)
|
|
|
|
|
translation_xml.appendChild(explanationList)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
explanation = doc.createElement("explanation")
|
|
|
|
|
explanation.textContent = translation.explanation
|
|
|
|
|
translation_xml.appendChild(explanation)
|
|
|
|
|
|
|
|
|
|
return translation_xml
|
|
|
|
|
|
|
|
|
|
def _export_explanation_list(doc, lst):
|
|
|
|
|
result = doc.createElement('explanationList')
|
|
|
|
|
for explanation in lst:
|
|
|
|
|
result.appendChild(explanation.export(doc))
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _export_label_list(doc, lst):
|
|
|
|
|
result = doc.createElement("labelList")
|
|
|
|
|