grammar example with saved entry_xml

This commit is contained in:
matic_t 2020-08-11 07:41:47 -07:00
parent ec811028ab
commit 410054cdd6
2 changed files with 20 additions and 9 deletions

View File

@ -9,6 +9,7 @@ def export_to_xml(model):
def export_entry(entry):
console.log(entry)
parser = __new__(DOMParser())
doc = parser.parseFromString("<entry />", "text/xml")
entry_xml = doc.firstChild
@ -23,6 +24,9 @@ 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)
@ -54,11 +58,21 @@ def export_entry(entry):
lexunit.appendChild(lexeme)
head.appendChild(lexunit)
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 (grammar_category)
# entry.original_xml.querySelector("head grammar category").textContent
# grammar.appendChild(grammar_category)
# head.appendChild(grammar)
if len(entry.measure) > 0:
measure_list = doc.createElement("measureList")

View File

@ -23,15 +23,12 @@ class Entry(Data):
self.measure = {}
self.labels = []
self.senses = []
self.original_xml = None
def import_xml(self, entry_xml):
# console.log(entry_xml)
# xmlClone = entry_xml.cloneNode(True)
self.original_xml = entry_xml.cloneNode(True)
status = entry_xml.querySelector("head status")
# xmlClone.removeChild(status)
# console.log(xmlClone)
headword = entry_xml.querySelector("head headword lemma")
grammar = entry_xml.querySelector("head grammar category")