PRInt32 counter = 0; nsCOMPtr<nsIContent> child; while (NS_SUCCEEDED(element->ChildAt(counter++, getter_AddRefs(child))) && child) {
PRUint32 counter = 0; nsIContent *child; while ((child = element->GetChildAt(counter++))) {
handleNode(nsIDOMNode* aNode, txStylesheetCompiler* aCompiler){    nsresult rv = NS_OK;    PRUint16 nodetype;    aNode->GetNodeType(&nodetype);    switch (nodetype) {        case nsIDOMNode::ELEMENT_NODE:        {            nsCOMPtr<nsIContent> element = do_QueryInterface(aNode);            nsCOMPtr<nsINodeInfo> ni;            element->GetNodeInfo(getter_AddRefs(ni));            PRInt32 namespaceID = ni->GetNamespaceID();            nsCOMPtr<nsIAtom> localname = ni->GetNameAtom();            nsCOMPtr<nsIAtom> prefix = ni->GetPrefixAtom();            PRInt32 attsCount;            element->GetAttrCount(attsCount);            nsAutoArrayPtr<txStylesheetAttr> atts;            if (attsCount > 0) {                atts = new txStylesheetAttr[attsCount];                NS_ENSURE_TRUE(atts, NS_ERROR_OUT_OF_MEMORY);                PRInt32 counter;                for (counter = 0; counter < attsCount; ++counter) {                    txStylesheetAttr& att = atts[counter];                    element->GetAttrNameAt(counter, &att.mNamespaceID,                                           getter_AddRefs(att.mLocalName),                                           getter_AddRefs(att.mPrefix));                    element->GetAttr(att.mNamespaceID, att.mLocalName, att.mValue);                }            }            rv = aCompiler->startElement(namespaceID, localname, prefix, atts,                                         attsCount);            NS_ENSURE_SUCCESS(rv, rv);            // explicitly destroy the attrs here since we no longer need it            atts = nsnull;            PRInt32 childCount;            element->ChildCount(childCount);            if (childCount > 0) {                PRInt32 counter = 0;                nsCOMPtr<nsIContent> child;                while (NS_SUCCEEDED(element->ChildAt(counter++, getter_AddRefs(child))) && child) {                    nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(child);                    rv = handleNode(childNode, aCompiler);                    NS_ENSURE_SUCCESS(rv, rv);                }            }            rv = aCompiler->endElement();            NS_ENSURE_SUCCESS(rv, rv);            break;        }        case nsIDOMNode::CDATA_SECTION_NODE:        case nsIDOMNode::TEXT_NODE:        {            nsAutoString chars;            aNode->GetNodeValue(chars);            rv = aCompiler->characters(chars);            NS_ENSURE_SUCCESS(rv, rv);            break;        }        case nsIDOMNode::DOCUMENT_NODE:        {            nsCOMPtr<nsIDocument> document = do_QueryInterface(aNode);            PRInt32 childCount;            document->GetChildCount(childCount);            if (childCount > 0) {                PRInt32 counter = 0;                nsCOMPtr<nsIContent> child;                while (NS_SUCCEEDED(document->ChildAt(counter++, getter_AddRefs(child))) && child) {                    nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(child);                    rv = handleNode(childNode, aCompiler);                    NS_ENSURE_SUCCESS(rv, rv);                }            }            break;        }    }    return NS_OK;}