I have this example xml file
Chapter 1
Welcome to Chapter 1
For working (navigating, searching, and modifying) with XML or HTML data, I found Beautiful library very useful. For installation problem or detailed information, click on link.
To find Attribute (tag) or multi-attribute values:
from bs4 import BeautifulSoup
data = """
PALS SOCIETY OF
CANADA
13479 77 AVE
"""
soup = BeautifulSoup(data, "lxml")
page_tag = soup.find_all('page')
details_tag = page_tag[0].find_all('text')
details_tag_count = len(details_tag)
for iter_text in range(details_tag_count):
print("Text : ", details_tag[iter_text].text)
print("Left tag : ", details_tag[iter_text].get("left"))
Output:
Text : PALS SOCIETY OF CANADA
Left tag : 135
Text : 13479 77 AVE
Left tag : None