Is the candidate node an ancestor of this node?
| Return Type | Function name | Arguments |
|---|---|---|
| bool | hzXmlNode::IsAncestor | (hzXmlNode*,) |
Declared in file: hzDocument.h
Defined in file : hzDocXml.cpp
Function Logic:
Function body:
bool hzXmlNode::IsAncestor (hzXmlNode* candidate)
{
// Is the candidate node an ancestor of this node?
//
// Arguments: 1) candidate The XML node to be tested as an ancestor of this node
//
// Returns: True If the candidate node is an ancestor of this
// False Otherwise
hzXmlNode* pNode ; // XML node pointer
// This node cannot have a non-ancestor.
if (!candidate)
return false ;
// If this node is at the same or lower level than the candidate then the candidate cannot be an ancestor of this node.
if (m_nLevel <&eq; candidate->m_nLevel)
return false ;
// Starting at the this node's level we work back to the candidate node's level.
for (pNode = this ; pNode->m_nLevel > candidate->m_nLevel ; pNode = pNode->Parent()) ;
// Now pNode is on the same level as the candidate. If the pNode and the candidate are the same node, the candidate is an ancestor
// of this node.
return pNode == candidate ? true : false ;
}