-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathxml_parse.py
32 lines (24 loc) · 974 Bytes
/
xml_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__author__ = 'Robert'
"""
from:
http://stackoverflow.com/questions/27003762/python-displaying-variable-with-multiple-xml-tags-inside-message-box
"""
import sys
sys.path.append('..')
# Import our modules here.
import easygui as eg
import lxml.etree as etree
# Get our XML file here.
# From: http://msdn.microsoft.com/en-us/library/ms762271%28v=vs.85%29.aspx
doc = etree.parse('books.xml')
# Grab the item tag and display the child tags name, description, and status.
for catalog in doc.getiterator('catalog'):
books = list()
for item in catalog.getiterator('book'):
item_name = item.findtext('title')
item_desc = item.findtext('description')
item_status = item.findtext('publish_date')
# Create a variable that adds the above child tags together.
books.append('{0} | {1} | {2}'.format(item_name, item_desc, item_status))
# Create message box to display print_xml.
eg.msgbox('\n'.join(books), title="XML Reader")