// removing redundant nodes with no elements
DOMNodeList* unitChildren = m_p_root->getChildNodes();
for ( unsigned u = 1; u < unitChildren->getLength(); ++u )
{
    DOMNode* node = unitChildren->item ( u );
    if ( node->getNodeType() == DOMNode::ELEMENT_NODE )
    {
        bool validChild = false;
        DOMElement* childElement = reinterpret_cast<DOMElement*>( node );
        DOMNode* childNode = childElement->getFirstChild();
        while ( childNode )
        {
            if ( childNode->getNodeType() == DOMNode::ELEMENT_NODE )
            {
                // child has valid element children
                validChild = true;
            }
            childNode = childNode->getNextSibling();
        }
        if ( !validChild )
        {
            // node has no valid children elements -> remove
            DOMNode* removed = m_p_root->removeChild ( node );
            removed->release();
        }
    }
}

Resolved. 
The key is: checking which type of node has which kind of children.

-mh

Reply via email to