{ const char* uri; aProperty->GetValue(&uri); treeItem->SetAttribute(kNameSpaceID_RDF, kPropertyAtom, uri, PR_FALSE); }
RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,                                  nsIRDFResource* aProperty,                                  nsIRDFResource* aValue,                                  PRInt32 aNaturalOrderPos){    // If it's a tree property, then we need to add the new child    // element to a special "children" element in the parent.  The    // child element's value will be the value of the    // property. We'll also attach an "ID=" attribute to the new    // child; e.g.,    //    // <xul:treeitem>    //   ...    //   <xul:treechildren>    //     <xul:treeitem RDF:ID="value">    //        <xul:treerow>    //           <xul:treecell RDF:ID="column1">    //              <!-- value not specified until SetCellValue() -->    //           </xul:treecell>    //    //           </xul:treecell RDF:ID="column2"/>    //              <!-- value not specified until SetCellValue() -->    //           </xul:treecell>    //    //           ...    //    //        </xul:treerow>    //    //        <!-- Other content recursively generated -->    //    //     </xul:treeitem>    //   </xul:treechildren>    //   ...    // </xul:treeitem>    //    // We can also handle the case where they've specified RDF    // contents on the <xul:treebody> tag, in which case we'll just    // dangle the new row directly off the treebody.    nsresult rv;    nsCOMPtr<nsIContent> treeChildren;    if (IsWidgetElement(aElement)) {        // Ensure that the <xul:treechildren> element exists on the parent.        if (NS_FAILED(rv = EnsureElementHasGenericChild(aElement,                                                        kNameSpaceID_XUL,                                                        kTreeChildrenAtom,                                                        getter_AddRefs(treeChildren))))            return rv;    }    else if (IsWidgetInsertionRootElement(aElement)) {        // We'll just use the <xul:treebody> as the element onto which        // we'll dangle a new row.        treeChildren = do_QueryInterface(aElement);        if (! treeChildren) {            NS_ERROR("aElement is not nsIContent!?!");            return NS_ERROR_UNEXPECTED;        }    }    else {        NS_ERROR("new tree row doesn't fit here!");        return NS_ERROR_UNEXPECTED;    }    // Create the <xul:treeitem> element    nsCOMPtr<nsIContent> treeItem;    if (NS_FAILED(rv = CreateResourceElement(kNameSpaceID_XUL,                                             kTreeItemAtom,                                             aValue,                                             getter_AddRefs(treeItem))))        return rv;    // Create the cell substructure    if (NS_FAILED(rv = CreateTreeItemCells(treeItem)))        return rv;    // Add the <xul:treeitem> to the <xul:treechildren> element.    treeChildren->AppendChildTo(treeItem, PR_TRUE);    // Add miscellaneous attributes by iterating _all_ of the    // properties out of the resource.    nsCOMPtr<nsIRDFArcsOutCursor> arcs;    if (NS_FAILED(rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)))) {        NS_ERROR("unable to get arcs out");        return rv;    }    PRBool markAsContainer = PR_FALSE;    while (NS_SUCCEEDED(rv = arcs->Advance())) {        nsCOMPtr<nsIRDFResource> property;        if (NS_FAILED(rv = arcs->GetPredicate(getter_AddRefs(property)))) {            NS_ERROR("unable to get cursor value");            return rv;        }        // Ignore properties that are used to indicate "tree-ness"        if (IsContainmentProperty(aElement, property))        {            markAsContainer = PR_TRUE;            continue;        }        PRInt32 nameSpaceID;        nsCOMPtr<nsIAtom> tag;        if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) {            NS_ERROR("unable to split property");            return rv;        }        nsCOMPtr<nsIRDFNode> value;        if (NS_FAILED(rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)))) {            NS_ERROR("unable to get target");            return rv;        }        nsCOMPtr<nsIRDFResource> resource;        nsCOMPtr<nsIRDFLiteral> literal;        nsAutoString s;        if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, getter_AddRefs(resource)))) {            const char* uri;            resource->GetValue(&uri);            s = uri;        }        else if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, getter_AddRefs(literal)))) {            const PRUnichar* p;            literal->GetValue(&p);            s = p;        }        else {            NS_ERROR("not a resource or a literal");            return NS_ERROR_UNEXPECTED;        }        treeItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE);        if (aNaturalOrderPos > 0)	    {            // XXX Add this to menu builder as well, or better yet, abstract out.		    nsAutoString	pos, zero("0000");		    pos.Append(aNaturalOrderPos, 10);		    if (pos.Length() < 4)		    {			    pos.Insert(zero, 0, 4-pos.Length()); 		    }		    treeItem->SetAttribute(kNameSpaceID_None, kNaturalOrderPosAtom, pos, PR_FALSE);	    }    }    if (NS_FAILED(rv) && (rv != NS_ERROR_RDF_CURSOR_EMPTY)) {        NS_ERROR("error advancing cursor");        return rv;    }    if (markAsContainer == PR_TRUE)    {        // Finally, mark this as a "container" so that we know to        // recursively generate kids if they're asked for.        if (NS_FAILED(rv = treeItem->SetAttribute(kNameSpaceID_RDF, kContainerAtom, "true", PR_FALSE)))            return rv;    }    return NS_OK;}