def parseClass(inString, rootClass):
    """
    This method parses the XML document given in the `parseClass` parameter
    assuming that it is an instance of the class given in the `rootClass`
    template. This is needed because in some cases the XML element name
    isn't enough to determine the correct class. For example, if the
    XML element name is `version` then the class can be `VersionCaps`
    or `Version`, depending on where from the API the document was
    retrieved.
    """
    from StringIO import StringIO
    doc = parsexml_(StringIO(inString))
    rootNode = doc.getroot()
    if rootClass is None:
        roots = get_root_tag(rootNode)
        rootClass = roots[1]
        if rootClass is None:
            rootClass = KeyValuePair
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    doc = None
    return rootObj
