if (NS_FAILED(rv = AddAttribute(element, property, value))) { NS_ERROR("unable to add attribute to element");
else if (NS_FAILED(rv)) {  NS_ERROR("problem iterating properties");
RDFXULBuilderImpl::CreateHTMLElement(nsIRDFResource* aResource,                                     nsIAtom* aTag,                                     nsIContent** aResult){    nsresult rv;    // XXX This is where we go out and create the HTML content. It's a    // bit of a hack: a bridge until we get to a more DOM-based    // solution.    nsCOMPtr<nsIHTMLContent> element;    if (NS_FAILED(rv = NS_CreateHTMLElement(getter_AddRefs(element), aTag->GetUnicode()))) {        NS_ERROR("unable to create HTML element");        return rv;    }    {        // Force the document to be set _here_. Many of the        // AppendChildTo() implementations do not recursively ensure        // that the child's doc is the same as the parent's.        nsCOMPtr<nsIDocument> doc;        if (NS_FAILED(rv = mDocument->QueryInterface(kIDocumentIID, getter_AddRefs(doc)))) {            NS_ERROR("uh, this isn't a document!");            return rv;        }        if (NS_FAILED(rv = element->SetDocument(doc, PR_FALSE))) {            NS_ERROR("couldn't set document on the element");            return rv;        }    }    // Now iterate through all the properties and add them as    // attributes on the element.  First, create a cursor that'll    // iterate through all the properties that lead out of this    // resource.    nsCOMPtr<nsIRDFArcsOutCursor> properties;    if (NS_FAILED(rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(properties)))) {        NS_ERROR("unable to create arcs-out cursor");        return rv;    }    // Advance that cursor 'til it runs outta steam    while (NS_SUCCEEDED(rv = properties->Advance())) {        nsCOMPtr<nsIRDFResource> property;        if (NS_FAILED(rv = properties->GetPredicate(getter_AddRefs(property)))) {            NS_ERROR("unable to get property from cursor");            return rv;        }        // These are special beacuse they're used to specify the tree        // structure of the XUL: ignore them b/c they're not attributes        if ((property.get() == kRDF_instanceOf) ||            (property.get() == kRDF_nextVal) ||            (property.get() == kRDF_type))            continue;        // XXX TODO Move this out of this loop, and use a cursor        // coughed up by NS_NewContainerCursor(), so we're sure that        // these get created in the right order.        // Recursively generate child nodes NOW: we can't "dummy" up        // nsIHTMLContent.        if (rdf_IsOrdinalProperty(property)) {            CreateHTMLContents(element, aResource);            continue;        }        // For each property, get its value: this will be the value of        // the new attribute.        nsCOMPtr<nsIRDFNode> value;        if (NS_FAILED(rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(value)))) {            NS_ERROR("unable to get value for property");            return rv;        }        // Add the attribute to the newly constructed element        if (NS_FAILED(rv = AddAttribute(element, property, value))) {            NS_ERROR("unable to add attribute to element");            return rv;        }    }    if (rv == NS_ERROR_RDF_CURSOR_EMPTY) {        rv = NS_OK;    }    else if (NS_FAILED(rv)) {        // uh oh...        NS_ERROR("problem iterating properties");        return rv;    }    if (NS_FAILED(rv = element->QueryInterface(kIContentIID, (void**) aResult))) {        NS_ERROR("unable to get nsIContent interface");        return rv;    }    return NS_OK;}