code: def to_element(self, root_name=None):
          
          if not root_name:
              root_name = self.nodename
          elem = ElementTreeBuilder.Element(root_name)
          for attrname in self.serializable_attributes():
              # Only use values that have been loaded into the internal
              # __dict__. For retrieved objects we look into the XML response at
              # access time, so the internal __dict__ contains only the elements
              # that have been set on the client side.
              try:
                  value = self.__dict__[attrname]
              except KeyError:
                  continue
  
              if attrname in self.xml_attribute_attributes:
                  elem.attrib[attrname] = six.text_type(value)
              else:
                  sub_elem = self.element_for_value(attrname, value)
                  elem.append(sub_elem)
  
          return elem
docs: Serialize this `Resource` instance to an XML element.