Artificial intelligent assistant

python3.x xmlデータ作成で text中にタグを複数挿入したい python3.x xml text ... <root><aaa><bbb></bbb><ccc></ccc></aaa></root> import xml.etree.ElementTree as ET temp = "<root/>" root = ET.fromstring(temp) temp = "<aaa><bbb></bbb><ccc></ccc></aaa>" root.append(ET.fromstring(temp)) ET.dump(root) * * * import xml.etree.ElementTree as ET temp = "<root/>" root = ET.fromstring(temp) aaa = ET.SubElement(root, 'aaa') aaa.text = "<bbb></bbb><ccc></ccc>" ET.dump(root) #<root><aaa>&lt;bbb&gt;&lt;/bbb&gt;&lt;ccc&gt;&lt;/ccc&gt;</aaa></root> * * * text append import xml.etree.ElementTree as ET temp = "<root/>" root = ET.fromstring(temp) aaa = ET.SubElement(root, 'aaa') aaa.text = "" bbb = ET.SubElement(aaa, 'bbb') bbb.text = "" aaa.text = "" #<root><aaa><bbb></bbb></aaa></root>

XMLtext, tail
text
tail

Python
Elementtext,tail


import xml.etree.ElementTree as ET
temp = ""
root = ET.fromstring(temp)
aaa = ET.SubElement(root, 'aaa')
aaa.text = ""
bbb = ET.SubElement(aaa, 'bbb')
bbb.text = ""
bbb.tail = ""
ccc = ET.SubElement(aaa, 'ccc')
ccc.text = ""
ccc.tail = ""

ET.dump(root)
#

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy ed4f80f28165b340fd2f7465643394c8