xml element tree to html problem

Ron Adam rrr at ronadam.com
Tue Apr 4 15:48:30 EDT 2006


I'm new to element tree and haven't been able to find a simple solution 
to this problem yet.  So maybe someone can point me in the right direction.

I have an element tree structure of nested elements that I want to 
convert to html as nested definition and unordered lists in the 
following way.

     <object>
        <name>ball</ball>
        <desc>
           <color>red</color>
           <size>large</size>
        </desc>
     </object>


To...

     <dl class='object'>
        <dt class='name'>ball</dt>
        <dd class='desc'>
           <ul>
              <li class='color'>red</li>
              <li class='size'>large</li>
           </ul>
        </dd>
     </dl>


Where each xml tag has a predefined relationship to either definition 
list  or an unordered list html tag.  'object' is always mapped to <dl 
class='object'>,  'name' is always mapped to <dt class='name'>.  etc...

So I will probably have a dictionary to look them up.  The problem I 
have is finding a relatively painless way to do the actual translation.

Thanks in advance for any advise.

Cheers,
    Ron




More information about the Python-list mailing list