element->GetAttribute(kNameSpaceID_XUL,
element->GetAttribute(kNameSpaceID_None,
RDFXULBuilderImpl::CreateXULElement(nsIRDFResource* aResource,                                    PRInt32 aNameSpaceID,                                    nsIAtom* aTag,                                    nsIContent** aResult){    nsresult rv;    nsCOMPtr<nsIContent> element;    if (NS_FAILED(rv = CreateResourceElement(aNameSpaceID,                                             aTag,                                             aResource,                                             getter_AddRefs(element)))) {        NS_ERROR("unable to create new content element");        return rv;    }    // Set the document for this XUL element.  It must be set now    // in order for event handlers to be detected in the subsequent    // SetAttribute calls.    nsCOMPtr<nsIDocument> document( do_QueryInterface(mDocument) );    element->SetDocument(document, PR_FALSE);    // 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) ||            rdf_IsOrdinalProperty(property))            continue;        // For each property, set its value.        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;    }    // Make it a container so that its contents get recursively    // generated on-demand.    if (NS_FAILED(rv = element->SetAttribute(kNameSpaceID_RDF, kContainerAtom, "true", PR_FALSE))) {        NS_ERROR("unable to make element a container");        return rv;    }    // There are some tags that we need to pay extra-special attention to...    if (aTag == kTreeAtom) {        nsAutoString dataSources;        if (NS_CONTENT_ATTR_HAS_VALUE ==            element->GetAttribute(kNameSpaceID_XUL,                                  kDataSourcesAtom,                                  dataSources)) {            rv = CreateTreeBuilder(element, dataSources);            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add datasources");        }    }    // Finally, assign the newly constructed element to the result    // pointer and addref it for the trip home.    *aResult = element;    NS_ADDREF(*aResult);    return NS_OK;}