Changeset 853 for TI07-MOLES/trunk


Ignore:
Timestamp:
27/04/06 17:07:47 (13 years ago)
Author:
lawrence
Message:

Including our simple xml pretty printer in browse utilities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/Utilities.py

    r845 r853  
    6666                return rr 
    6767        else: return rr[0]  
     68 
     69def PrettyPrint(elem,indent='',html=0,space='   '): 
     70        '''Lightweight pretty printing of elementTree elements''' 
     71        def estrip(elem): 
     72                ''' Just want to get rid of unwanted whitespace ''' 
     73                if elem is None: 
     74                        return '' 
     75                else: 
     76                        return elem.strip() 
     77        strAttrib='' 
     78        for att in elem.attrib: 
     79                strAttrib+=' %s="%s"'%(att,elem.attrib[att]) 
     80        result='%s<%s%s>%s'%(indent,elem.tag,strAttrib,estrip(elem.text)) 
     81        children=len(elem) 
     82        if children: 
     83                for item in elem: 
     84                        result+='\n'+PrettyPrint(item,indent=indent+space) 
     85                result+='\n%s%s</%s>'%(indent,estrip(item.tail),elem.tag) 
     86        else: 
     87                result+='</%s>'%(elem.tag) 
     88        return result 
Note: See TracChangeset for help on using the changeset viewer.