NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor"); if (rv == NS_RDF_NO_VALUE) continue;
rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,                     nsIRDFResource* aContainer,                     nsIRDFNode* aElement,                     PRInt32* aIndex){    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;    NS_PRECONDITION(aIndex != nsnull, "null ptr");    if (! aIndex)        return NS_ERROR_NULL_POINTER;    nsresult rv;    nsCOMPtr<nsIRDFAssertionCursor> elements;    if (NS_FAILED(rv = NS_NewContainerCursor(aDataSource,                                             aContainer,                                             getter_AddRefs(elements)))) {        NS_ERROR("unable to create container cursor");        return rv;    }    // Advance the cursor until we find the element we want    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 get element from cursor");            return rv;        }        // Okay, we've found it.        nsCOMPtr<nsIRDFResource> ordinal;        if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {            NS_ERROR("unable to get element's ordinal index");            return rv;        }        PRInt32 index;        if (NS_FAILED(rv = rdf_OrdinalResourceToIndex(ordinal, &index))) {            NS_ERROR("unable to convert ordinal resource to index");            return rv;        }        if (element != nsCOMPtr<nsIRDFNode>( do_QueryInterface(aElement)) )            continue;        *aIndex = index;        return NS_OK;    }    NS_WARNING("element not found");    *aIndex = -1;    return NS_OK;}