if (NS_SUCCEEDED(rv = GetDOMNodeResource(aParent, getter_AddRefs(parent)))) {
if (NS_SUCCEEDED(rv = GetRDFResourceFromXULElement(aParent, getter_AddRefs(parent)))) {
RDFXULBuilderImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild){    NS_PRECONDITION(aParent != nsnull, "null ptr");    if (!aParent)        return NS_ERROR_NULL_POINTER;    NS_PRECONDITION(aNewChild != nsnull, "null ptr");    if (!aNewChild)        return NS_ERROR_NULL_POINTER;    nsresult rv;    // XXX If aNewChild doesn't have a resource, then somebody is    // appending a non-RDF element into aParent. Panic for now.    nsCOMPtr<nsIRDFResource> newChild;    if (NS_FAILED(rv = GetDOMNodeResource(aNewChild, getter_AddRefs(newChild)))) {        NS_ERROR("new child doesn't have a resource");        return rv;    }    // If there was an old parent for newChild, then make sure to    // remove that relationship.    nsCOMPtr<nsIDOMNode> oldParentNode;    if (NS_FAILED(rv = aNewChild->GetParentNode(getter_AddRefs(oldParentNode)))) {        NS_ERROR("unable to get new child's parent");        return rv;    }    if (oldParentNode) {        nsCOMPtr<nsIRDFResource> oldParent;        // If the old parent has a resource...        if (NS_SUCCEEDED(rv = GetDOMNodeResource(oldParentNode, getter_AddRefs(oldParent)))) {            // ...and it's a XUL element...            PRBool isXULElement;            if (NS_SUCCEEDED(rv = mDB->HasAssertion(oldParent,                                                    kRDF_instanceOf,                                                    kXUL_element,                                                    PR_TRUE,                                                    &isXULElement))                && isXULElement) {                // remove the child from the old collection                if (NS_FAILED(rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild))) {                    NS_ERROR("unable to remove newChild from oldParent");                    return rv;                }            }        }    }    // If the new parent has a resource...    nsCOMPtr<nsIRDFResource> parent;    if (NS_SUCCEEDED(rv = GetDOMNodeResource(aParent, getter_AddRefs(parent)))) {        // ...and it's a XUL element...        PRBool isXULElement;        if (NS_SUCCEEDED(rv = mDB->HasAssertion(parent,                                                kRDF_instanceOf,                                                kXUL_element,                                                PR_TRUE,                                                &isXULElement))            && isXULElement) {            // ...then append it to the container            if (NS_FAILED(rv = rdf_ContainerAppendElement(mDB, parent, newChild))) {                NS_ERROR("unable to insert new element into container");                return rv;            }        }    }    return NS_OK;}