nsAutoString id; rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id); if (NS_FAILED(rv)) return rv;
if (! isAnonymous) { #endif  nsXPIDLCString uri; rv = aResource->GetValue( getter_Copies(uri) ); if (NS_FAILED(rv)) return rv;  nsAutoString id; rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id); if (NS_FAILED(rv)) return rv;
RDFXULBuilderImpl::CreateHTMLElement(nsINameSpace* aContainingNameSpace,                                     nsIRDFResource* aResource,                                     nsIAtom* aTagName,                                     nsIContent** aResult){    nsresult rv;    // XXX This is where we go out and create the HTML content. It's a    // bit of a hack: a bridge until we get to a more DOM-based    // solution.    nsCOMPtr<nsIHTMLContent> element;    const PRUnichar *unicodeString;    aTagName->GetUnicode(&unicodeString);    rv = mHTMLElementFactory->CreateInstanceByTag(unicodeString,                                                  getter_AddRefs(element));    if (NS_FAILED(rv)) return rv;    // XXX This is part of what will be an optimal solution.  To allow    // elements that expect to be inside a form to work without forms, we    // will create a secret hidden form up in the XUL document.  Only    // do this if the new HTML element is a form control element.    // Eventually we'll really want to be tracking all forms full force.    nsCOMPtr<nsIFormControl> htmlFormControl = do_QueryInterface(element);    if (htmlFormControl) {        // Retrieve the hidden form from the XUL document.        nsCOMPtr<nsIDOMHTMLFormElement> htmlFormElement;        mDocument->GetForm(getter_AddRefs(htmlFormElement));              // Set the form        htmlFormControl->SetForm(htmlFormElement);    }    // Force the document to be set _here_. Many of the    // AppendChildTo() implementations do not recursively ensure    // that the child's doc is the same as the parent's.    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);    if (! doc)        return NS_ERROR_UNEXPECTED;    // Set the document.    rv = element->SetDocument(doc, PR_FALSE);    NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't set document on the element");    if (NS_FAILED(rv)) return rv;    if (aResource) {        // Set the 'id' attribute        nsXPIDLCString uri;        rv = aResource->GetValue( getter_Copies(uri) );        if (NS_FAILED(rv)) return rv;        nsAutoString id;        rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id);        if (NS_FAILED(rv)) return rv;               rv = element->SetAttribute(kNameSpaceID_None, kIdAtom, id, PR_FALSE);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set element's ID");        if (NS_FAILED(rv)) return rv;        // Since we didn't notify when setting the 'id' attribute, we        // need to explicitly add ourselves to the resource-to-element        // map. XUL elements don't need to do this, because they've        // got a hacked SetAttribute() method...        rv = mDocument->AddElementForResource(aResource, element);        if (NS_FAILED(rv)) return rv;        // Now iterate through all the properties and add them as        // attributes on the element.  First, create a cursor that'll        // iterate through all the properties that lead out of this        // resource.        nsCOMPtr<nsISimpleEnumerator> properties;        rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(properties));        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create arcs-out cursor");        if (NS_FAILED(rv)) return rv;        // Advance that cursor 'til it runs outta steam        while (1) {            PRBool hasMore;            rv = properties->HasMoreElements(&hasMore);            if (NS_FAILED(rv)) return rv;            if (! hasMore)                break;            nsCOMPtr<nsISupports> isupports;            rv = properties->GetNext(getter_AddRefs(isupports));            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get property from cursor");            if (NS_FAILED(rv)) return rv;            // Skip any properties that aren't meant to be added to            // the content model.            nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);            if (! IsAttributeProperty(property))                continue;            // For each property, get its value: this will be the value of            // the new attribute.            nsCOMPtr<nsIRDFNode> value;            rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(value));            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get value for property");            if (NS_FAILED(rv)) return rv;            NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor");            if (rv == NS_RDF_NO_VALUE)                continue;            // Add the attribute to the newly constructed element            rv = AddAttribute(element, property, value);            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add attribute to element");            if (NS_FAILED(rv)) return rv;        }        // Create the children NOW, because we can't do it lazily.        rv = CreateHTMLContents(aContainingNameSpace, element, aResource);        NS_ASSERTION(NS_SUCCEEDED(rv), "error creating child contents");        if (NS_FAILED(rv)) return rv;        // Check for a 'datasources' tag, in which case we'll create a        // template builder.        {            nsAutoString dataSources;            if (NS_CONTENT_ATTR_HAS_VALUE ==                element->GetAttribute(kNameSpaceID_None,                                      kDataSourcesAtom,                                      dataSources)) {                nsCOMPtr<nsIRDFContentModelBuilder> builder;                rv = CreateTemplateBuilder(element, dataSources, getter_AddRefs(builder));                NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add datasources");                // Force construction of template content _now_.                rv = builder->CreateContents(element);                if (NS_FAILED(rv)) return rv;            }        }    }        // ...and finally, return the result.    rv = element->QueryInterface(kIContentIID, (void**) aResult);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get nsIContent interface");    if (NS_FAILED(rv)) return rv;    return NS_OK;}