Add the supplied node to the calling node's list of child node. This is achieved by either making m_pChildren equal to the supplied node (where the calling node does not yet have chidren) or by seeking to the end of the list and then appending (each of the existing children will have its m_pSibling pointer set to the next child).
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzXmlNode::AddNode | (hzXmlNode*,) |
Declared in file: hzDocument.h
Defined in file : hzDocXml.cpp
Function Logic:
Function body:
hzEcode hzXmlNode::AddNode (hzXmlNode* pNode)
{
// Add the supplied node to the calling node's list of child node.
//
// This is achieved by either making m_pChildren equal to the supplied node (where the calling node does not yet have chidren) or by
// seeking to the end of the list and then appending (each of the existing children will have its m_pSibling pointer set to the next
// child).
//
// Arguments: 1) pNode The node to be added to this node's list of child nodes
//
// Returns: E_ARGUMENT If no node is supplied
// E_DUPLICATE If the supplied node is this node
// E_OK If the node is added as a child
_hzfunc("hzXmlNode::AddNode") ;
hzXmlNode* tmp ; // XML node pointer
// uint32_t nodeNo ; // Node number
if (!pNode)
return hzerr(E_ARGUMENT, "Attempt to add a null node to %s", txtName()) ;
if (pNode == this)
return hzerr(E_DUPLICATE, "Attempt to add a node (%d) to itself (%d, %s)", pNode->m_Uid, m_Uid, txtName()) ;
if (!m_pHostDoc)
hzexit(E_NOINIT, "Node has no host document") ;
m_pHostDoc->m_NodesPar.Insert(m_Uid, pNode->m_Uid) ;
if (!m_Children)
m_Children = pNode->GetUid() ;
else
{
for (tmp = GetFirstChild() ; tmp->m_Sibling ; tmp = tmp->Sibling())
{
if (pNode == tmp)
return hzerr(E_DUPLICATE, "Attempt to add an already existing node to %s", txtName()) ;
}
// for (nodeNo = m_Children ; nodeNo ; nodeNo = tmp->m_Sibling)
// {
// tmp = m_pHostDoc->m_arrNodes.InSitu(nodeNo) ;
// if (!tmp->m_Sibling)
// break ;
// if (pNode == tmp)
// return hzerr(E_DUPLICATE, "Attempt to add an already existing node to %s", txtName()) ;
// }
tmp->m_Sibling = pNode->m_Uid ;
}
return E_OK ;
}