nsAutoString uri; if (NS_FAILED(rv = aElement->GetAttribute(kNameSpaceID_RDF, kIdAtom, uri))) { NS_ERROR("severe error retrieving attribute"); return rv; }  if (rv != NS_CONTENT_ATTR_HAS_VALUE) { NS_ERROR("tree element has no RDF:ID"); return NS_ERROR_UNEXPECTED; }
RDFXULBuilderImpl::CreateContents(nsIContent* aElement){    nsresult rv;    // See if someone has marked the element's contents as being    // generated: this prevents a re-entrant call from triggering    // another generation.    nsAutoString attrValue;    if (NS_FAILED(rv = aElement->GetAttribute(kNameSpaceID_None,                                              kXULContentsGeneratedAtom,                                              attrValue))) {        NS_ERROR("unable to test contents-generated attribute");        return rv;    }    if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (attrValue.EqualsIgnoreCase("true")))        return NS_OK;    // Get the treeitem's resource so that we can generate cell    // values. We could QI for the nsIRDFResource here, but doing this    // via the nsIContent interface allows us to support generic nodes    // that might get added in by DOM calls.    nsAutoString uri;    if (NS_FAILED(rv = aElement->GetAttribute(kNameSpaceID_RDF,                                              kIdAtom,                                              uri))) {        NS_ERROR("severe error retrieving attribute");        return rv;    }    if (rv != NS_CONTENT_ATTR_HAS_VALUE) {        NS_ERROR("tree element has no RDF:ID");        return NS_ERROR_UNEXPECTED;    }    nsCOMPtr<nsIRDFResource> resource;    if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri, getter_AddRefs(resource)))) {        NS_ERROR("unable to create resource");        return rv;    }    // Ignore any elements that aren't XUL elements: we can't    // construct content for them anyway.    PRBool isXULElement;    if (NS_FAILED(rv = mDB->HasAssertion(resource, kRDF_instanceOf, kXUL_element, PR_TRUE, &isXULElement))) {        NS_ERROR("unable to determine if element is a XUL element");        return rv;    }    if (! isXULElement)        return NS_OK;    // If it's a XUL element, it'd better be an RDF Sequence...    NS_ASSERTION(rdf_IsContainer(mDB, resource), "element is a XUL:element, but not an RDF:Seq");    if (! rdf_IsContainer(mDB, resource))        return NS_ERROR_UNEXPECTED;    // Now mark the element's contents as being generated so that    // any re-entrant calls don't trigger an infinite recursion.    if (NS_FAILED(rv = aElement->SetAttribute(kNameSpaceID_None,                                              kXULContentsGeneratedAtom,                                              "true",                                              PR_FALSE))) {        NS_ERROR("unable to set contents-generated attribute");        return rv;    }    // Iterate through all of the element's children, and construct    // appropriate children for each arc.    nsCOMPtr<nsIRDFAssertionCursor> children;    if (NS_FAILED(rv = NS_NewContainerCursor(mDB, resource, getter_AddRefs(children)))) {        NS_ERROR("unable to create cursor for children");        return rv;    }    while (NS_SUCCEEDED(rv = children->Advance())) {        nsCOMPtr<nsIRDFNode> child;        if (NS_FAILED(rv = children->GetObject(getter_AddRefs(child)))) {            NS_ERROR("error reading cursor");            return rv;        }        if (NS_FAILED(AppendChild(aElement, child))) {            NS_ERROR("problem appending child to content model");            return rv;        }    }    if (rv == NS_ERROR_RDF_CURSOR_EMPTY)        rv = NS_OK;    return rv;}