def create_element(tag, attributes=None, sub_elements=None):
 if tag:
  elem = XmlET.Element(tag)
  if attributes:
   for (k, v) in attributes.items():
    elem.set(k, v)
  if sub_elements:
   for (k, v) in sub_elements.items():
    if v:
     if (k == 'packages'):
      for v_tuple in v:
       sub_elem = XmlET.SubElement(elem, 'package')
       (sub_elem_name, sub_elem_version) = v_tuple
       sub_elem.set('name', sub_elem_name)
       sub_elem.set('version', sub_elem_version)
     elif isinstance(v, list):
      sub_elem = XmlET.SubElement(elem, k)
      for v_tuple in v:
       if (len(v_tuple) == 2):
        v_tag = v_tuple[0]
        v_text = v_tuple[1]
        if v_text:
         v_elem = XmlET.SubElement(sub_elem, v_tag)
         v_elem.text = v_text
     else:
      sub_elem = XmlET.SubElement(elem, k)
      sub_elem.text = v
  return elem
 return None

def create_element ( tag , attributes = None , sub_elements = None ) : if tag : elem = XmlET . Element ( tag ) if attributes : for ( k , v ) in attributes . items ( ) : elem . set ( k , v ) if sub_elements : for ( k , v ) in sub_elements . items ( ) : if v : if ( k == 'packages' ) : for v_tuple in v : sub_elem = XmlET . SubElement ( elem , 'package' ) ( sub_elem_name , sub_elem_version ) = v_tuple sub_elem . set ( 'name' , sub_elem_name ) sub_elem . set ( 'version' , sub_elem_version ) elif isinstance ( v , list ) : sub_elem = XmlET . SubElement ( elem , k ) for v_tuple in v : if ( len ( v_tuple ) == 2 ) : v_tag = v_tuple [ 0 ] v_text = v_tuple [ 1 ] if v_text : v_elem = XmlET . SubElement ( sub_elem , v_tag ) v_elem . text = v_text else : sub_elem = XmlET . SubElement ( elem , k ) sub_elem . text = v return elem return None
create a new element whose tag is the value of the received tag .