Hi Kent,

Well I have decided to get this sorted once and for all. Not that I
don't like ElementTree, but the fack is that BeautifulSoup uses a near
identical syntax to the 3D application SDK's object model I'm using it
with, making interaction between the 3D and the XML extremely
transparent. Anyway, here is what I did.

I simply modified the BeautifulSoup class, and added my own nestable
tags to the list of NESTABLE_BLOCK_TAGS:

NESTABLE_BLOCK_TAGS = ['blockquote', 'div', 'fieldset', 'ins', 'del']

became

NESTABLE_BLOCK_TAGS = ['blockquote', 'div', 'fieldset', 'ins', 'del',
'sceneobject', 'parameters', 'parameter', 'shader']


Not super-elegant but it works. I wrote to the author but did not get an answer.


Thanks everyone!
Bernard



On 9/28/05, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Bernard Lebel wrote:
> > Hi Kent,
> >
> > Thanks a lot for that answer. I have had a look at the BS code, and I
> > have to admit I'm a bit at a loss: how would you add several nestable
> > tag names in that list?
> >
> > I tried
> > NESTABLE_TAGS = BeautifulSoup.buildTagMap( [], 'parameter', 'parameters' )
> > for example, but I kept having these nesting issues. I fact I have a
> > whole bunch of tags that I need to make nestable....
>
> I think that's right but I confess I don't understand that part of the code 
> too well either. Maybe an email to the author? or maybe it's time to try 
> ElementTree (and pdis XPath?) again.
>
> Kent
>
> >
> >
> > Thanks
> > Bernard
> >
> >
> > On 9/26/05, Kent Johnson <[EMAIL PROTECTED]> wrote:
> >
> >>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
> >>
> >>_______________________________________________
> >>Tutor maillist  -  Tutor@python.org
> >>http://mail.python.org/mailman/listinfo/tutor
> >>
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to