我有一些问题要从这个 xml 中读取信息:
<entry number="50" date="2011-01-29">
<name>Info text about account</name>
<row account="1930" debit="0" credit="2051"/>
<row account="1471" debit="410" credit="0"/>
<row account="4404" debit="1641" credit="0"/>
</entry>
我使用此代码
def printInfoOfVerification():
valFound = 0
print("Now system will print information about a verification nr in xml:")
val = input("Enter verification number: ")
verificationNumbr = xmltree.iter('entry')
for i in verificationNumbr:
if (i.attrib['number']) == val:
valFound = 1
print("Verification number:",val, "found")
print("Info about verification:")
print(i.attrib['date'])
if valFound == 0:
print("Verification number not found:",val)
如果“val”= 50,这将产生:
Verification number: 50 found
Info about verification:
2011-01-29
但问题是,我还想打印标签“name”中的信息,所以对于这个例子,它应该是这样的:
Verification number: 50 found
Info about verification:
2011-01-29
Info text about account
我试图用 xmltree.iter('name') 和其他方式读取名称标签,但没有成功:(有人知道该怎么做吗?谢谢