Join XML strings pulled from the web using python
I'm trying to join two xml files I'm pulling from the web. I just need the
second XML file to be added at the end of the first. To this this I've
tried to pull the XML from the web, convert them to strings, join them
then create a new tree from the conjoined string.
urls = 'http://www.w3schools.com/xml/guestbook.asp',
'http://www.w3schools.com/xml/guestbook.asp'
for url in urls:
url = url[0]
XML = requests.get(url)
XML_str = XML.content + XML_str
XML_data = ET.fromstring(XML_str)
tree = ET.ElementTree(XML_data)
However when I do this I get the following error.
Error: lxml.etree.XMLSyntaxError: XML declaration allowed only at the
start of the document, line 1, column 326
The XML string looks fine to me and I think the error is realted to there
being two declaratoin lines form each feed (e.g. )
does anyone know a better way to join two XML files being pulled from the
web without writing to disk....?
No comments:
Post a Comment