【发布时间】:2017-01-30 09:14:12
【问题描述】:
import xml.etree.ElementTree as ET
tree = ET.parse("Parsed.xml")
doc = tree.getroot()
for elem in doc.findall('.//medicationsInfo/entryInfo/productCode/code'):
print (elem.text);
for elem in doc.findall('.//medicationsInfo/entryInfo/productCode/codeSystem'):
print (elem.text);
在上面的 python 代码中,我通过指定路径获取 code 和 codeSystem 的值,但它们首先打印所有代码,然后打印所有 codeSystem。我想并行打印它们(如按列打印),那么如何编辑上述代码以解析我的 xml 文档。
例如,我以这种方式拥有 xml,我想按列打印 code 和 codeSystem。
【问题讨论】:
标签: python xml-parsing elementtree