Ian Bicking: the old part of his blog

Re: XML Processing

maybe BeautifulSoup is what you need: http://www.crummy.com/software/BeautifulSoup/

Comment on XML Processing
by Lawrence Oluyede

Comments:

AFAIK, BeautifulSoup structures aren't writable, which is what I'm doing -- parsing HTML, modifying the parsed form (adding comments), then writing it out again.

# Ian Bicking

You can change BeautifulSoup structures. For example, you can insert raw html fragments:

>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup('<html><body><p> text 1 <p> text 2 </html>')
>>> print soup
<html><body><p> text 1 </p><p> text 2 </p></body></html>
>>> par2 = soup('p')[1]
>>> par2.name = 'div'
>>> par2.contents = ['<p>'] + par2.contents + ['</p>']
>>> print soup
<html><body><p> text 1 </p><div><p> text 2 </p></div></body></html>
# Alexander Kozlovsky