code: def generate_guids(root):
      
      from hashlib import md5
  
      # specify which tags need a guid and in which attribute this should be stored.
      needs_id = { 'Product'   : 'Id',
                   'Package'   : 'Id',
                   'Component' : 'Guid',
                 }
  
      # find all XMl nodes matching the key, retrieve their attribute, hash their
      # subtree, convert hash to string and add as a attribute to the xml node.
      for (key,value) in needs_id.items():
          node_list = root.getElementsByTagName(key)
          attribute = value
          for node in node_list:
              hash = md5(node.toxml()).hexdigest()
              hash_str = '%s-%s-%s-%s-%s' % ( hash[:8], hash[8:12], hash[12:16], hash[16:20], hash[20:] )
              node.attributes[attribute] = hash_str
docs: generates globally unique identifiers for parts of the xml which need
      them.
  
      Component tags have a special requirement. Their UUID is only allowed to
      change if the list of their contained resources has changed. This allows
      for clean removal and proper updates.
  
      To handle this requirement, the uuid is generated with an md5 hashing the
      whole subtree of a xml node.