[Tutor] Problem with BeautifulSoup

Kent Johnson kent37 at tds.net
Mon Sep 26 12:09:07 CEST 2005


Bernard Lebel wrote:
> Hi grouchy,
> 
> I seem to have found the problem. Somehow, it seems BeautifulSoup
> doesn't like nested tags of the same name.

This seems to be a feature of BS. It seems a bit of a misfeature when applied to XML but anyway...you can configure BS with a set of tags which can be nested, then it will properly parse your data. Here is a short program that shows how:

xml = '''<parameter scriptname="posx">
    <fcurve plotted="False">
          <parameter scriptname="extrapolation">1</parameter>
    </fcurve>
</parameter>'''

import BeautifulSoup

class NestingParser(BeautifulSoup.BeautifulStoneSoup):
    NESTABLE_TAGS = BeautifulSoup.buildTagMap([], 'parameter')
    
soup = NestingParser(xml)
print soup.prettify()


Kent



More information about the Tutor mailing list