You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
720 B
27 lines
720 B
|
1 week ago
|
from xml.etree.ElementTree import parse
|
||
|
|
from lxml import etree
|
||
|
|
|
||
|
|
with open(r"C:\Users\roger\Desktop\a.xml", 'r', encoding='utf-8') as f:
|
||
|
|
xml_data = f.read().encode('gbk')
|
||
|
|
print(xml_data)
|
||
|
|
|
||
|
|
# parse(r"C:\Users\roger\Desktop\a.xml")
|
||
|
|
parser = etree.XMLParser(encoding="utf-8")
|
||
|
|
tree = etree.parse(r"C:\Users\roger\Desktop\a.xml", parser=parser)
|
||
|
|
root = tree.getroot()
|
||
|
|
print(root)
|
||
|
|
result = etree.tostring(tree, pretty_print=True, encoding='utf-8')
|
||
|
|
print(result)
|
||
|
|
|
||
|
|
# r = etree.(tree, 'result')
|
||
|
|
|
||
|
|
# for i in r.iterfind('halls'):
|
||
|
|
# print(i)
|
||
|
|
|
||
|
|
for i in root:
|
||
|
|
print(i.tag, i.attrib)
|
||
|
|
if i.tag == 'halls':
|
||
|
|
for c in i:
|
||
|
|
print(c.tag, c.text, c.attrib)
|
||
|
|
id = c.get('id')
|
||
|
|
print(id)
|