rv = rdfDoc->AddElementForResource(resource, this);
rv = rdfDoc->AddElementForResource(resource, NS_STATIC_CAST(nsIStyledContent*, this));
RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep){    if (aDocument == mDocument)        return NS_OK;    nsresult rv;    nsCOMPtr<nsIRDFDocument> rdfDoc;    if (mDocument) {        // Need to do a GetResource() here, because changing the document        // may actually change the element's URI.        nsCOMPtr<nsIRDFResource> resource;        GetResource(getter_AddRefs(resource));        // Remove this element from the RDF resource-to-element map in        // the old document.        if (resource) {            if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {                rv = rdfDoc->RemoveElementForResource(resource, this);                NS_ASSERTION(NS_SUCCEEDED(rv), "error unmapping resource from element");            }        }        // Release the named reference to the script object so it can        // be garbage collected.        if (mScriptObject) {            nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();            if (nsnull != owner) {                nsIScriptContext *context;                if (NS_OK == owner->GetScriptContext(&context)) {                    context->RemoveReference((void *) &mScriptObject,                                             mScriptObject);                    NS_RELEASE(context);                }                NS_RELEASE(owner);            }        }    }    mDocument = aDocument; // not refcounted    if (mDocument) {        // Need to do a GetResource() here, because changing the document        // may actually change the element's URI.        nsCOMPtr<nsIRDFResource> resource;        GetResource(getter_AddRefs(resource));        // Add this element to the RDF resource-to-element map in the        // new document.        if (resource) {            if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {                rv = rdfDoc->AddElementForResource(resource, this);                NS_ASSERTION(NS_SUCCEEDED(rv), "error mapping resource to element");            }        }        // Add a named reference to the script object.        if (mScriptObject) {            nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();            if (nsnull != owner) {                nsIScriptContext *context;                if (NS_OK == owner->GetScriptContext(&context)) {                    nsAutoString tag;                    mTag->ToString(tag);                    char buf[64];                    char* p = buf;                    if (tag.Length() >= sizeof(buf))                        p = new char[tag.Length() + 1];                    context->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);                    if (p != buf)                        delete[] p;                    NS_RELEASE(context);                }                NS_RELEASE(owner);            }        }    }    if (aDeep && mChildren) {        for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {            // XXX this entire block could be more rigorous about            // dealing with failure.            nsISupports* obj = mChildren->ElementAt(i);            PR_ASSERT(obj);            if (! obj)                continue;            nsIContent* child;            if (NS_SUCCEEDED(obj->QueryInterface(kIContentIID, (void**) &child))) {                child->SetDocument(aDocument, aDeep);                NS_RELEASE(child);            }            NS_RELEASE(obj);        }    }    return NS_OK;}