child->SetAttribute(kNameSpaceID_None, kURIAtom, NS_ConvertASCIItoUCS2(aURLStr.GetBuffer(), aURLStr.Length()), PR_FALSE);
nsAutoString url; child->GetAttribute(kNameSpaceID_None, kURIAtom, url); if (url.IsEmpty()) child->SetAttribute(kNameSpaceID_None, kURIAtom, NS_ConvertASCIItoUCS2(aURLStr.GetBuffer(), aURLStr.Length()), PR_FALSE);
NS_IMETHODIMP nsXBLService::GetBinding(const nsCString& aURLStr, nsIXBLBinding** aResult){  *aResult = nsnull;  if (aURLStr.IsEmpty())    return NS_ERROR_FAILURE;  // XXX Obtain the # marker and remove it from the URL.  nsCAutoString uri(aURLStr);  PRInt32 indx = uri.RFindChar('#');  nsCAutoString ref;   uri.Right(ref, uri.Length() - (indx + 1));  uri.Truncate(indx);  nsCOMPtr<nsIDocument> doc;    GetBindingDocument(uri, getter_AddRefs(doc));  if (!doc)    return NS_ERROR_FAILURE;  // We have a doc. Obtain our specific binding element.  // Walk the children looking for the binding that matches the ref  // specified in the URL.  nsCOMPtr<nsIContent> root = getter_AddRefs(doc->GetRootContent());  if (!root)    return NS_ERROR_FAILURE;  nsAutoString bindingName; bindingName.AssignWithConversion( NS_STATIC_CAST(const char*, ref) );  PRInt32 count;  root->ChildCount(count);  for (PRInt32 i = 0; i < count; i++) {    nsCOMPtr<nsIContent> child;    root->ChildAt(i, *getter_AddRefs(child));    nsAutoString value;    child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::id, value);        // If no ref is specified just use this.    if ((bindingName.IsEmpty()) || (bindingName == value)) {      child->SetAttribute(kNameSpaceID_None, kURIAtom, NS_ConvertASCIItoUCS2(aURLStr.GetBuffer(), aURLStr.Length()), PR_FALSE);      // Make a new binding      NS_NewXBLBinding(aResult);      // Initialize its bound element.      (*aResult)->SetBindingElement(child);      // Check for the presence of an extends attribute      child->GetAttribute(kNameSpaceID_None, kExtendsAtom, value);      if (!value.IsEmpty()) {        // See if we are extending a builtin tag.        nsCOMPtr<nsIAtom> tag;        (*aResult)->GetBaseTag(getter_AddRefs(tag));        if (!tag) {          // We have a base class binding. Load it right now.          nsCOMPtr<nsIXBLBinding> baseBinding;          nsCAutoString url; url.AssignWithConversion(value);          GetBinding(url, getter_AddRefs(baseBinding));          if (!baseBinding)            return NS_OK; // At least we got the derived class binding loaded.          (*aResult)->SetBaseBinding(baseBinding);        }      }      break;    }  }  return NS_OK;}