if ((nameSpaceID == kNameSpaceID_None) && (nameAtom.get() == kRefAtom)) {      PRInt32 count; rv = element->ChildCount(count); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's child count"); if (NS_FAILED(rv)) return rv;  while (--count >= 0) { nsCOMPtr<nsIContent> child; rv = element->ChildAt(count, *getter_AddRefs(child)); if (NS_FAILED(rv)) return rv;  rv = element->RemoveChildAt(count, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child");  if (! IsXULElement(child)) {    rv = child->SetDocument(nsnull, PR_TRUE); if (NS_FAILED(rv)) return rv; } }    rv = element->UnsetAttribute(kNameSpaceID_None, kItemContentsGeneratedAtom, PR_FALSE); if (NS_FAILED(rv)) return rv;    rv = element->UnsetAttribute(kNameSpaceID_None, kXULContentsGeneratedAtom, PR_FALSE); if (NS_FAILED(rv)) return rv;  rv = element->SetAttribute(kNameSpaceID_RDF, kContainerAtom, "true", PR_FALSE); if (NS_FAILED(rv)) return rv;   }
RDFXULBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName, const nsString& aValue){    nsresult rv;    nsCOMPtr<nsIRDFResource> resource;    if (NS_FAILED(rv = GetRDFResourceFromXULElement(aElement, getter_AddRefs(resource)))) {        // XXX it's not a resource element, so there's no assertions        // we need to make on the back-end. Should we just do the        // update?        return NS_OK;    }    // Make sure it's a XUL element; otherwise, we really don't have    // any business with the attribute.    PRBool isXULElement;    rv = mDB->HasAssertion(resource,                           kRDF_instanceOf,                           kXUL_element,                           PR_TRUE,                           &isXULElement);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to determine if element is a XUL element");    if (NS_FAILED(rv)) return rv;    if (! isXULElement)        return NS_OK;    // Okay, so it _is_ a XUL element. Deal with it.    // Get the nsIContent interface, it's a bit more utilitarian    nsCOMPtr<nsIContent> element( do_QueryInterface(aElement) );    if (! element) {        NS_ERROR("element doesn't support nsIContent");        return NS_ERROR_UNEXPECTED;    }    // Split the property name into its namespace and tag components    PRInt32  nameSpaceID;    nsCOMPtr<nsIAtom> nameAtom;    rv = element->ParseAttributeString(aName, *getter_AddRefs(nameAtom), nameSpaceID);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to parse attribute string");    if (NS_FAILED(rv)) return rv;    // Check for "special" properties that may wreak havoc on the    // content model.    if ((nameSpaceID == kNameSpaceID_None) && (nameAtom.get() == kIdAtom)) {        // They're changing the ID of the element.        // XXX Punt for now.        PR_LOG(gLog, PR_LOG_ALWAYS,               ("ignoring id change on XUL element"));        return NS_OK;    }    else if (nameSpaceID == kNameSpaceID_RDF) {        if (nameAtom.get() == kDataSourcesAtom) {            NS_NOTYETIMPLEMENTED("can't change the data sources yet");            return NS_ERROR_NOT_IMPLEMENTED;        }        // XXX we should probably just ignore any changes to rdf: attribute        PR_LOG(gLog, PR_LOG_ALWAYS,               ("changing an rdf: attribute; this is probably not a good thing"));        return NS_OK;    }    // If we get here, it's a vanilla property that we need to go into    // the RDF graph to update. So, build an RDF resource from the    // property name...    nsCOMPtr<nsIRDFResource> property;    if (kNameSpaceID_Unknown == nameSpaceID) {      nameSpaceID = kNameSpaceID_None;  // ignore unknown prefix XXX is this correct?    }    rv = GetResource(nameSpaceID, nameAtom, getter_AddRefs(property));    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to construct resource");    if (NS_FAILED(rv)) return rv;    // See if there was an old value    nsAutoString oldValueStr;    nsCOMPtr<nsIRDFLiteral> oldvalue;    rv = element->GetAttribute(nameSpaceID, nameAtom, oldValueStr);    if (NS_FAILED(rv)) return rv;    if (NS_CONTENT_ATTR_HAS_VALUE == rv) {        rv = gRDFService->GetLiteral(oldValueStr.GetUnicode(), getter_AddRefs(oldvalue));        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to construct literal");        if (NS_FAILED(rv)) return rv;    }    // Get the new value    nsCOMPtr<nsIRDFLiteral> newvalue;    rv = gRDFService->GetLiteral(aValue.GetUnicode(), getter_AddRefs(newvalue));    if (NS_FAILED(rv)) return rv;    // Depending on whether or not there was an old value, we'll    // either do a "change" or an "assert".    if (oldvalue) {        rv = mDB->Change(resource, property, oldvalue, newvalue);        NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to change new property value");        if (NS_FAILED(rv)) return rv;    }    else {        rv = mDB->Assert(resource, property, newvalue, PR_TRUE);        NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert new property value");        if (NS_FAILED(rv)) return rv;    }    return NS_OK;}