def _CreateClassFromElementTree(target_class, tree, namespace=None, tag=None):
  """Instantiates the class and populates members according to the tree.

  Note: Only use this function with classes that have _namespace and _tag
  class members.

  Args:
    target_class: class The class which will be instantiated and populated
        with the contents of the XML.
    tree: ElementTree An element tree whose contents will be converted into
        members of the new target_class instance.
    namespace: str (optional) The namespace which the XML tree's root node must
        match. If omitted, the namespace defaults to the _namespace of the
        target class.
    tag: str (optional) The tag which the XML tree's root node must match. If
        omitted, the tag defaults to the _tag class member of the target
        class.

    Returns:
      An instance of the target class - or None if the tag and namespace of
      the XML tree's root node did not match the desired namespace and tag.
  """
  if namespace is None:
    namespace = target_class._namespace
  if tag is None:
    tag = target_class._tag
  if tree.tag == '{%s}%s' % (namespace, tag):
    target = target_class()
    target._HarvestElementTree(tree)
    return target
  else:
    return None