Fredrik Lundh wrote:

> here's one way to do it:
> 
>     import cElementTree as ET
> 
>     tree = ET.XML("""
>     <object>
>         <name>ball</name>
>         <desc>
>             <color>red</color>
>             <size>large</size>
>         </desc>
>     </object>
>     """)
> 
>     MAP = {
>         "object": ("dl", "object"),
>         "name":   ("dt", "name"),
>         "desc":   ("ul", None),
>         "color":  ("li", "color"),
>         "size":   ("li", "size"),
>     }
> 
>     for elem in tree.getiterator():
>         elem.tag, klass = MAP[elem.tag]
>         if klass:
>             elem.set("class", klass)
> 
>     print ET.tostring(tree)


Thanks a *LOT!*  :-)

This is what I needed.  Now I can play with finding the best data 
structure along with what elements to translate each tag to.

This is for a rewrite of PyDoc.py.  I'm hoping it will be as easy to 
write to other formats from the XML as it is to html.

Cheers,
    Ron
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to