从xml here可以看到,有多个<item>
节点具有一组子节点,例如<summary>
、<status>
和{
我遇到的问题是,在使用minidom时,有可能获得firstChild和lastChild的值,但不一定要在两者之间有任何值。在
我已经创建了下面的工作,但我认为这是一个接近我需要做的事情
import xml.dom.minidom
xml = xml.dom.minidom.parse(result) # or xml.dom.minidom.parseString(xml_string)
itemList = xml.getElementsByTagName('item')
for item in itemList [1:]:
summaryList = item.getElementsByTagName('summary')
statusList = item.getElementsByTagName('status')
keyList = item.getElementsByTagName('key')
lineText = (summaryList[0].nodeValue + " " + statusList[0].nodeValue + " " + keyList[0].nodeValue)
p = Paragraph(lineText, style)
Story.append(p)
定义连接所有文本子节点的
get_text()
函数(请参见this answer):印刷品:
^{pr2}$希望有帮助。在
像这样的东西怎么样
相关问题 更多 >
编程相关推荐