Activity 15.2.1.
What is the last thing (last line of text) that will be printed when the code below runs?
'''), as well as the triple double quote ("""), allow for the creation of strings in Python that span multiple lines.
fromstring converts the string representation of the XML into a โtreeโ of XML elements. When the XML is in a tree, we have a series of methods we can call to extract portions of data from the XML string. The find function searches through the XML tree and retrieves the element that matches the specified tag. The get gets the value of the attribute in that tag.
ElementTree has the advantage that while the XML in this example is quite simple, it turns out there are many rules regarding valid XML, and using ElementTree allows us to extract data from XML without worrying about the rules of XML syntax.
get to get the value of an attributeget to get the value of an attribute?
get to get the value of an attribute and if the attribute isnโt there the default is to return None.
find to get the first element of the XML of a specified type. You can the use find on that element to get children tags of that element.
tree rather than in book? Modify the code to see what happens.