rv = CreateWidgetItem(element, aProperty, newresource, PR_TRUE, nsnull );
rv = CreateWidgetItem(element, aProperty, newresource, PR_TRUE, nsnull , nsnull );
RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource,                                nsIRDFResource* aProperty,                                nsIRDFNode* aOldTarget,                                nsIRDFNode* aNewTarget){    // Just silently fail, because this can happen "normally" as part    // of tear-down code. (Bug 9098)    if (! mDocument)        return NS_OK;    nsresult rv;	if (mCache)	{		if (aOldTarget)		{			// XXX fix this: in-memory DS doesn't like a null oldTarget			mCache->Change(aSource, aProperty, aOldTarget, aNewTarget);		}		else		{			// XXX should get tv via observer interface			mCache->Assert(aSource, aProperty, aNewTarget, PR_TRUE);		}	}    nsCOMPtr<nsISupportsArray> elements;    rv = NS_NewISupportsArray(getter_AddRefs(elements));    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create new ISupportsArray");    if (NS_FAILED(rv)) return rv;    // Find all the elements in the content model that correspond to    // aSource: for each, we'll try to build XUL children if    // appropriate.    rv = GetElementsForResource(aSource, elements);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to retrieve elements from resource");    if (NS_FAILED(rv)) return rv;    PRUint32 cnt;    rv = elements->Count(&cnt);    if (NS_FAILED(rv)) return rv;    for (PRInt32 i = cnt - 1; i >= 0; --i) {        nsISupports* isupports = elements->ElementAt(i);        nsCOMPtr<nsIContent> element( do_QueryInterface(isupports) );        NS_IF_RELEASE(isupports);                // XXX somehow figure out if building XUL kids on this        // particular element makes any sense whatsoever.        // We'll start by making sure that the element at least has        // the same parent has the content model builder's root        if (!IsElementInWidget(element))            continue;        LOG("change", element, aSource, aProperty, aNewTarget);                nsCOMPtr<nsIRDFResource> oldresource = do_QueryInterface(aOldTarget);        if (oldresource && IsContainmentProperty(element, aProperty)) {            // Okay, the object _is_ a resource, and the predicate is            // a containment property. So we'll need to remove the old            // item from the widget, and then add the new one.            // But if the contents of aElement _haven't_ yet been            // generated, then just ignore: nothing is in the content            // model to remove.            PRBool contentsGenerated;            nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(element);            if (xulcontent) {                rv = xulcontent->GetLazyState(nsIXULContent::eContainerContentsBuilt, contentsGenerated);                if (NS_FAILED(rv)) return rv;            }            else {                // HTML is always generated                contentsGenerated = PR_TRUE;            }            if (! contentsGenerated)                return NS_OK;            // Okay, it's a "live" element, so go ahead and remove the            // child from this node.            rv = RemoveWidgetItem(element, aProperty, oldresource, PR_TRUE);            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove widget item");            if (NS_FAILED(rv)) return rv;            nsCOMPtr<nsIRDFResource> newresource = do_QueryInterface(aNewTarget);            // XXX Tough. We don't handle the case where they've            // changed a resource to a literal. But this is            // bizarre anyway.            if (! newresource)                return NS_OK;            rv = CreateWidgetItem(element, aProperty, newresource, PR_TRUE, nsnull /* don't care */);            if (NS_FAILED(rv)) return rv;        }        else {            // Either the target of the assertion is not a resource,            // or the target is a resource and the property is not a            // containment property. So this won't be an item in the            // widget. See if we need to tear down some substructure            // on the current element.            nsAutoString templateID;            rv = element->GetAttribute(kNameSpaceID_None,                                       kTemplateAtom,                                       templateID);            if (NS_FAILED(rv)) return rv;            if (rv == NS_CONTENT_ATTR_HAS_VALUE) {                nsCOMPtr<nsIDOMXULDocument>    xulDoc;                xulDoc = do_QueryInterface(mDocument);                if (! xulDoc)                    return NS_ERROR_UNEXPECTED;                nsCOMPtr<nsIDOMElement>    domElement;                rv = xulDoc->GetElementById(templateID, getter_AddRefs(domElement));                NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find template node");                if (NS_FAILED(rv)) return rv;                nsCOMPtr<nsIContent> templateNode = do_QueryInterface(domElement);                if (! templateNode)                    return NS_ERROR_UNEXPECTED;                // this node was created by a XUL template, so update it accordingly                rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aNewTarget);                if (NS_FAILED(rv)) return rv;            }        }    }    return NS_OK;}