if (NS_SUCCEEDED(rv = mDB->HasAssertion(parent, kRDF_instanceOf, kXUL_element, PR_TRUE, &isXULElement)) && isXULElement) {
if (isXULElement) {
RDFXULBuilderImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild){    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;    NS_PRECONDITION(aOldChild != nsnull, "null ptr");    if (!aOldChild)        return NS_ERROR_NULL_POINTER;    nsresult rv;    // Translate each of the DOM nodes into the RDF resource for which    // they are acting as a proxy. This implementation will only    // update nodes that are an RDF:instanceOf a XUL:element.    // XXX If aNewChild doesn't have a resource, then somebody is    // inserting 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;    }    // XXX ibid    nsCOMPtr<nsIRDFResource> oldChild;    if (NS_FAILED(rv = GetDOMNodeResource(aOldChild, getter_AddRefs(oldChild)))) {        NS_ERROR("old child doesn't have a resource");        return rv;    }    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) {            // Remember the old child's index...            PRInt32 index;            if (NS_FAILED(rv = rdf_ContainerIndexOf(mDB, parent, oldChild, &index))) {                NS_ERROR("unable to get index of old child in container");                return rv;            }            // ...then remove the old child from the old collection...            if (NS_FAILED(rv = rdf_ContainerRemoveElement(mDB, parent, oldChild))) {                NS_ERROR("unable to remove old child from container");                return rv;            }            // ...and add the new child to the collection at the old child's index            if (NS_FAILED(rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index))) {                NS_ERROR("unable to add new child to container");                return rv;            }        }    }    return NS_OK;}