Beispiel #1
0
 def string_to_description(self, value):
     s = "<description>" + value + "</description>"
     try:
         dom = parseString(s)
     except xml.parsers.expat.ExpatError:
         raise NotValid
     desc_element = dom.getElementsByTagName("description")[0]
     # Here, I am assuming that the content of the description element
     # is plain old XHTML; we have a namespace issue here; I need
     # to discuss that on the Picfolio mailing list
     # Setting the XHTML 1.0 namespace on all the elements
     for e in xmlutils.get_all_child_elements(desc_element):
         e.setAttribute("xmlns", "http://www.w3.org/1999/xhtml")
     return desc_element
Beispiel #2
0
 def get_description(self, nonone = 0):
     desc_element = self.__get_description_element()
     if desc_element == None:
         value = None
     else:
         if not desc_element.hasChildNodes():
             value = ""
         else:
             for e in xmlutils.get_all_child_elements(desc_element):
                 if e.hasAttribute("xmlns"):
                     e.removeAttribute("xmlns")
             value = desc_element.toxml()
             value = re.sub("^<description>|</description>$", "",
                            value)
     if nonone and value == None:
         value = ""
     return value