from BeautifulSoup import BeautifulStoneSoup
xml_data = """
<doc>
<test>test</test>
<foo:bar>Hello world!</foo:bar>
</doc>
"""
soup = BeautifulStoneSoup(xml_data)
print soup.prettify()
make = soup.find('foo:bar')
print make
make.contents = ['Top of the world Ma!']
print make
How to change the contents of an element, in this case the element in the "make" variable, without losing the contents? If you can point me to other pure python modules that can modify existing xml documents, please let me know.
PS! BeautifulSoup is great for screenshots and parsing of both HTML and XML!
source
share