I am writing a script that edits an XML file with BeautifulStoneSoup
, but the library converts all tags to lower case. Is there an option to conserve the case?
import BeautifulSoup
xml = "<TestTag>a string</TestTag>"
soup = BeautifulSoup.BeautifulStoneSoup(xml, markupMassage=False)
print soup.prettify() # or soup.renderContents()
#prints
>>> <testtag>a string</testtag>
#instead of the expected
>>> <TestTag>a string</TestTag>
You could use Beautiful Soup 4, as follows (requires the lxml XML library):
In [10]: from bs4 import BeautifulSoup
In [11]: xml = "<TestTag>a string</TestTag>"
In [12]: soup = BeautifulSoup(xml, "xml")
In [13]: print soup
<?xml version="1.0" encoding="utf-8"?>
<TestTag>a string</TestTag>
In [14]:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With