const PRUnichar *tagName; aTag->GetUnicode(&tagName);
nsXULTemplateBuilder::CreateElement(PRInt32 aNameSpaceID,                                    nsIAtom* aTag,                                    nsIContent** aResult){    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);    if (! doc)        return NS_ERROR_NOT_INITIALIZED;    nsresult rv;    nsCOMPtr<nsIContent> result;    if (aNameSpaceID == kNameSpaceID_XUL) {        rv = nsXULElement::Create(aNameSpaceID, aTag, getter_AddRefs(result));        if (NS_FAILED(rv)) return rv;    }    else if (aNameSpaceID == kNameSpaceID_HTML) {        const PRUnichar *tagName;        aTag->GetUnicode(&tagName);        rv = gHTMLElementFactory->CreateInstanceByTag(tagName, getter_AddRefs(result));        if (NS_FAILED(rv)) return rv;        if (! result)            return NS_ERROR_UNEXPECTED;    }    else {        const PRUnichar *tagName;        aTag->GetUnicode(&tagName);        nsCOMPtr<nsIElementFactory> elementFactory;        GetElementFactory(aNameSpaceID, getter_AddRefs(elementFactory));        rv = elementFactory->CreateInstanceByTag(tagName, getter_AddRefs(result));        if (NS_FAILED(rv)) return rv;        if (! result)            return NS_ERROR_UNEXPECTED;    }    //     nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(result);    if (formControl) {        nsCOMPtr<nsIDOMHTMLFormElement> form;        rv = mDocument->GetForm(getter_AddRefs(form));        if (NS_SUCCEEDED(rv) && form)            formControl->SetForm(form);    }        rv = result->SetDocument(doc, PR_FALSE);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set element's document");    if (NS_FAILED(rv)) return rv;    *aResult = result;    NS_ADDREF(*aResult);    return NS_OK;}