几天来,我一直在编写一个脚本,该脚本将检索 XML 文件中的标签并将其值输出到消息框。最初我打算使用 Tkinter,但我注意到它只会打印一组标签,所以我尝试使用 easygui,但我遇到了同样的问题。
我有相当多的编程经验,但我对 python 比较陌生,我在谷歌上做了几次搜索,但没有出现,所以我想我会在这里问。
这是代码中起作用的部分。
# Import our modules here.
import easygui as eg
import lxml.etree as etree
# Get our XML file here.
doc = etree.parse('file.xml')
# Grab the item tag and display the child tags name, description, and status.
for item in doc.getiterator('item'):
item_name = item.findtext('name')
item_desc = item.findtext('description')
item_status = item.findtext('status')
# Create a variable that adds the above child tags together.
print_xml = str((item_name + " | " + item_desc + " | " + item_status))
# Create message box to display print_xml.
eg.msgbox(print_xml, title="XML Reader")
提前致谢!