I am trying to use ElementTree with this sample data from Microsoft which I have just copied and paste into a string (perhaps naively).
I have input all of the XML data in a string as follows (this is a truncated example but I have used all the XML):
data2 = '''
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
etc
etc'''
Then used this code:
import xml.etree.ElementTree as ET
tree2 = ET.fromstring(data2)
print (tree2.find('author').text)
And I get this output:
ParseError: XML or text declaration not at start of entity: line 2, column 0
However, when I try a simple example it works:
data = '''
<p>
<name>Fred</name>
</p>'''
tree = ET.fromstring(data)
print (tree.find('name').text)
Out:
Fred
Is this because I have done a copy and paste or is my code incorrect? What am I doing wrong here?