result = container->RemoveChildAt(0, PR_FALSE);
nsIFormControl* childFormControl = nsnull; result = child->QueryInterface(kIFormControlIID, (void**)&childFormControl); if (NS_SUCCEEDED(result)) {  nsIDOMHTMLFormElement* formElem = nsnull; childFormControl->GetForm(&formElem);  result = container->RemoveChildAt(0, PR_FALSE);  childFormControl->SetForm(formElem);  NS_RELEASE(childFormControl); NS_IF_RELEASE(formElem); } else { result = container->RemoveChildAt(0, PR_FALSE); }
SinkContext::DemoteContainer(const nsIParserNode& aNode,                              nsIHTMLContent*& aParent){  nsresult result = NS_OK;  nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());  aParent = nsnull;  // Search for the nearest container on the stack of the  // specified type  PRInt32 stackPos = mStackPos-1;  while ((stackPos > 0) && (nodeType != mStack[stackPos].mType)) {    stackPos--;  }    // If we find such a container  if (stackPos > 0) {    nsIHTMLContent* container = mStack[stackPos].mContent;        // See if it has a parent on the stack. It should for all the    // cases for which this is called, but put in a check anyway    if (stackPos > 1) {      nsIHTMLContent* parent = mStack[stackPos-1].mContent;            // If the demoted container hasn't yet been appended to its      // parent, do so now.      if (0 == (mStack[stackPos].mFlags & APPENDED)) {        result = parent->AppendChildTo(container, PR_FALSE);      }           if (NS_SUCCEEDED(result)) {       // Move all of the demoted containers children to its parent       PRInt32 i, count;       container->ChildCount(count);              for (i = 0; i < count && NS_SUCCEEDED(result); i++) {         nsIContent* child;                  // Since we're removing as we go along, always get the         // first child         result = container->ChildAt(0, child);         if (NS_SUCCEEDED(result)) {           // Remove it from its old parent (the demoted container)           result = container->RemoveChildAt(0, PR_FALSE);           if (NS_SUCCEEDED(result)) {             result = parent->AppendChildTo(child, PR_FALSE);             SetDocumentInChildrenOf(child, mSink->mDocument);           }           NS_RELEASE(child);         }       }              // Remove the current element from the context stack,       // since it's been demoted.       while (stackPos < mStackPos-1) {         mStack[stackPos].mType = mStack[stackPos+1].mType;         mStack[stackPos].mContent = mStack[stackPos+1].mContent;         mStack[stackPos].mFlags = mStack[stackPos+1].mFlags;         stackPos++;       }       mStackPos--;     }     aParent = parent;     NS_ADDREF(parent);    }    NS_RELEASE(container);  }    return result;}