Example 6: Traversing the DOM tree in C++.

// Start with the root element
DOMNode* elem = (DOMNode*)doc->getDocumentElement();
// Iterate through the child elements
DOMNode* child = elem->getFirstChild();
while ( child != NULL ) {
  // Look for the "LastName" element
  char* szElem = child->getNodeName();
  if ( _stricmp( szElem, "LastName" ) == 0 )
  {
    // Found the element, now go through its
    // children and find the text value
    DOMNodeList* childNodes = child->getChildNodes();
    for ( UINT y = 0; 
          y < childNodes->getLength(); 
          y++ ) 
    {
      DOMNode* data = childNodes->item( y );
      if ( data->getNodeType() == DOMNode::TEXT_NODE )
        return (char*)data->getNodeValue();
    }
  }
  child = child->getNextSibling();
}