Changeset 5472


Ignore:
Timestamp:
08/07/09 17:35:13 (10 years ago)
Author:
cbyrom
Message:

Cope with different versions of Atoms - these may have their content
namespaces slightly differently specified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/models/Atom.py

    r5219 r5472  
    773773            else: 
    774774                logging.debug("No file data - adding contents of element instead") 
     775                # the div ns is sometimes handled differently - cope with both 
     776                # options 
    775777                divEl = contentTag.find('{%s}div'%ndgObject.XHTML_NS) 
    776                  
    777                 div = divEl.text 
    778                  
    779                 # NB, this can contain xhtml, so check for children 
    780                 for child in divEl.getchildren(): 
    781                     div += ET.tostring(child) 
    782  
    783                 # NB, Elementtree tends to revert the namespace of the xhtml 
    784                 # elements to the parent Atom NS - so switch this back 
    785                 div = div.replace(ndgObject.ATOM_NS, ndgObject.XHTML_NS) 
    786                 self.Content = div 
     778                if not divEl: 
     779                    divEl = contentTag.find('{%s}div'%ndgObject.ATOM_NS) 
     780                     
     781                if divEl: 
     782                    div = divEl.text 
     783                     
     784                    # NB, this can contain xhtml, so check for children 
     785                    for child in divEl.getchildren(): 
     786                        div += ET.tostring(child) 
     787     
     788                    # NB, Elementtree tends to revert the namespace of the xhtml 
     789                    # elements to the parent Atom NS - so switch this back 
     790                    div = div.replace(ndgObject.ATOM_NS, ndgObject.XHTML_NS) 
     791                    self.Content = div 
    787792         
    788793        range = tree.findtext('{%s}temporalRange' %ndgObject.MOLES_NS) 
Note: See TracChangeset for help on using the changeset viewer.