NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor"); if (rv == NS_RDF_NO_VALUE) continue;
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,                           nsIRDFResource* aContainer,                           nsIRDFNode* aElement){    NS_PRECONDITION(aDataSource != nsnull, "null ptr");    if (! aDataSource)        return NS_ERROR_NULL_POINTER;    NS_PRECONDITION(aContainer != nsnull, "null ptr");    if (! aContainer)        return NS_ERROR_NULL_POINTER;    NS_PRECONDITION(aElement != nsnull, "null ptr");    if (! aElement)        return NS_ERROR_NULL_POINTER;    nsresult rv;    // Create a cursor and grovel through the container looking for    // the specified element.    nsCOMPtr<nsIRDFAssertionCursor> elements;    if (NS_FAILED(rv = NS_NewContainerCursor(aDataSource,                                             aContainer,                                             getter_AddRefs(elements)))) {        NS_ERROR("unable to create container cursor");        return rv;    }    while (1) {        rv = elements->Advance();        if (NS_FAILED(rv))            return rv;        if (rv == NS_RDF_CURSOR_EMPTY)            break;        nsCOMPtr<nsIRDFNode> element;        if (NS_FAILED(rv = elements->GetTarget(getter_AddRefs(element)))) {            NS_ERROR("unable to read cursor");            return rv;        }        PRBool eq;        if (NS_FAILED(rv = element->EqualsNode(aElement, &eq))) {            NS_ERROR("severe error on equality check");            return rv;        }        if (! eq)            continue;        // Okay, we've found it.        // What was it's index?        nsCOMPtr<nsIRDFResource> ordinal;        if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {            NS_ERROR("unable to get element's ordinal index");            return rv;        }        // First, remove the element.        if (NS_FAILED(rv = aDataSource->Unassert(aContainer, ordinal, element))) {            NS_ERROR("unable to remove element from the container");            return rv;        }        PRInt32 index;        if (NS_FAILED(rv = rdf_OrdinalResourceToIndex(ordinal, &index))) {            NS_ERROR("unable to convert ordinal URI to index");            return rv;        }        // Now slide the rest of the collection backwards to fill in        // the gap.        while (1) {            rv = elements->Advance();            if (NS_FAILED(rv))                return rv;            if (rv == NS_RDF_CURSOR_EMPTY)                break;            if (NS_FAILED(rv = elements->GetTarget(getter_AddRefs(element)))) {                NS_ERROR("unable to get element from cursor");                return rv;            }            if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {                NS_ERROR("unable to get element's ordinal index");                return rv;            }            if (NS_FAILED(rv = aDataSource->Unassert(aContainer, ordinal, element))) {                NS_ERROR("unable to remove element from the container");                return rv;            }            if (NS_FAILED(rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal)))) {                NS_ERROR("unable to construct ordinal resource");                return rv;            }            if (NS_FAILED(rv = aDataSource->Assert(aContainer, ordinal, element, PR_TRUE))) {                NS_ERROR("unable to add element to the container");                return rv;            }            ++index;        }        // Update the container's nextVal to reflect this mumbo jumbo        if (NS_FAILED(rv = rdf_ContainerSetNextValue(aDataSource, aContainer, index))) {            NS_ERROR("unable to update container's nextVal");            return rv;        }        return NS_OK;    }    NS_WARNING("attempt to remove non-existant element from container");    return NS_OK;}