import bs4

# read in the xml file
soup = bs4.BeautifulSoup(open('Ode.xml'), 'html.parser')

# get the text content inside the "EEBO" tag
text = soup.find('eebo').get_text()

# print the text
print(text)

"""
Explanation: Next Steps with HTML Parsing
In our Introduction to HTML Parsing notebook, we learned the basics of extracting text data from HTML pages. This notebook builds on that foundation to help explore some of the more advanced features of BeautifulSoup and some of the more difficult use cases in which one might leverage BeautifulSoup.
Parsing XML
We've been focusing on "HTML" documents so far, but we can also use BeautifulSoup to parse "XML" documents. For example, the following snippet parses the ECCO TCP's XML version of David Garrick's "Ode on Dedicating a Building":
End of explanation
"""


import bs4

# read in the xml file
soup = bs4.BeautifulSoup(open('Ode.xml'), 'html.parser')

# get a list of the div1 tags
elems = soup.find_all('div1')

# iterate over the div1 tags in soup
for i in elems:
  
  # only proceed if the current tag has the attribute type="ode"
  if i['type'] == 'ode':
    
    # print the text content of this div1 element
    print(i.get_text())

"""
Explanation: <h2 style='color:green'>Reviewing XML Parsing</h2>

See if you can use the pattern displayed above to read in and then print the text within "Rom.xml". Note that this file does not contain an "eebo" tag.
Filtering Selections
Sometimes an HTML selection returns a mixture of elements we wish to process and others we wish to skip altogether. For example, suppose a web page has multiple div1 tags, and we only wish to parse some of them. In that case, we can use a conditional to ensure we only process the ones we care about. Let's see this in action:
End of explanation
"""


