NS_ERROR("unable to find child to remove");
NS_WARNING("unable to find child to remove");
RDFTreeBuilderImpl::RemoveWidgetItem(nsIContent* aElement,                                     nsIRDFResource* aProperty,                                     nsIRDFResource* aValue){    nsresult rv;    // We may put in a situation where we've been asked to either    // remove a xul:treeitem directly from a xul:treechildren (or    // xul:treebody) tag; or, we may be asked to remove a xul:treeitem    // from a grandparent xul:treeitem tag.    // Verify that the element is actually a xul:treeitem    PRInt32 nameSpaceID;    if (NS_FAILED(rv = aElement->GetNameSpaceID(nameSpaceID))) {        NS_ERROR("unable to get element's namespace ID");        return rv;    }    nsCOMPtr<nsIAtom> tag;    if  (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag)))) {        NS_ERROR("unable to get element's tag");        return rv;    }    nsCOMPtr<nsIContent> treechildren; // put it here so it stays in scope    if ((nameSpaceID == kNameSpaceID_XUL) && (tag.get() == kTreeItemAtom)) {        if (NS_FAILED(rv = FindChildByTag(aElement,                                          kNameSpaceID_XUL,                                          kTreeChildrenAtom,                                          getter_AddRefs(treechildren)))) {            // XXX make this a warning            NS_ERROR("attempt to remove child from an element with no treechildren");            return NS_OK;        }        aElement = treechildren.get();    }    // Now we assume that aElement is a xul:treebody or a    // xul:treechildren; we'll just make sure for kicks.    {        aElement->GetNameSpaceID(nameSpaceID);        NS_ASSERTION(kNameSpaceID_XUL == nameSpaceID, "not a xul:treebody or xul:treechildren");        if (kNameSpaceID_XUL != nameSpaceID)            return NS_ERROR_UNEXPECTED;        aElement->GetTag(*getter_AddRefs(tag));        NS_ASSERTION((kTreeBodyAtom == tag.get()) || (kTreeChildrenAtom == tag.get()),                     "not a xul:treebody or xul:treechildren");        if ((kTreeBodyAtom != tag.get()) && (kTreeChildrenAtom != tag.get()))            return NS_ERROR_UNEXPECTED;    }    // Allright, now grovel to find the doomed kid and blow it away.    PRInt32 count;    if (NS_FAILED(rv = aElement->ChildCount(count)))        return rv;    for (PRInt32 i = 0; i < count; ++i) {        nsCOMPtr<nsIContent> kid;        if (NS_FAILED(rv = aElement->ChildAt(i, *getter_AddRefs(kid))))            return rv; // XXX fatal        // Make sure it's a <xul:treeitem>        PRInt32 nameSpaceID;        if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID)))            return rv; // XXX fatal        if (nameSpaceID != kNameSpaceID_XUL)            continue; // wrong namespace        nsCOMPtr<nsIAtom> tag;        if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag))))            return rv; // XXX fatal        if (tag.get() != kTreeItemAtom)            continue; // wrong tag        // Now get the resource ID from the RDF:ID attribute. We do it        // via the content model, because you're never sure who        // might've added this stuff in...        nsCOMPtr<nsIRDFResource> resource;        if (NS_FAILED(rv = GetElementResource(kid, getter_AddRefs(resource)))) {            NS_ERROR("severe error retrieving resource");            return rv;        }        if (resource.get() != aValue)            continue; // not the resource we want        // Fount it! Now kill it.        if (NS_FAILED(rv = aElement->RemoveChildAt(i, PR_TRUE))) {            NS_ERROR("unable to remove xul:treeitem from xul:treechildren");            return rv;        }        return NS_OK;    }    // XXX make this a warning    NS_ERROR("unable to find child to remove");    return NS_OK;}