How To Remove Xml Header In Beautifulsoup?
I have imported and modified some xml, but when I write out my xml using test.prettify(). It changes the top line of the xml from to
Solution 1:
I'm sure there's a more elegant way to do this using BeautifulSoup's built-ins, but based on your comment, I'll give you the "strip it out" version:
xml_string = '<?xml version="1.0" encoding="utf-8"?>'
print xml_string[:xml_string.find("encoding")-1] + "?>"
This is general enough to strip out any encoding from the header (not just utf-8).
Solution 2:
You could find the xml and use replaceWith()
to replace it with the value you want.
Post a Comment for "How To Remove Xml Header In Beautifulsoup?"