我想分割一个分号分隔的字符串,以便使用Python将每个单独的字符串存储为XML标记之间的文本。字符串值如下所示:08-26-2009;08-27-2009;08-29-2009
它们只是存储为字符串值的日期
我想遍历每个值,存储到一个变量,并在最后将该变量调用到以下代码中:for element in iter:
# Look for a tag called "Timeinfo"
if element.tag == "timeinfo":
tree = root.find(".//timeinfo")
# Clear all tags below "timeinfo"
tree.clear()
element.append(ET.Element("mdattim"))
child1 = ET.SubElement(tree, "sngdate")
child2 = ET.SubElement(child1, "caldate1")
child3 = ET.SubElement(child1, "caldate2")
child4 = ET.SubElement(child1, "caldate3")
child2.text = FIRST DATE VARIABLE GOES HERE
child2.text = SECOND DATE VARIABLE GOES HERE
child2.text = THIRD DATE VARIABLE GOES HERE
如有任何帮助,我们将不胜感激。