----------------------------------------------------------------------------- Create a new element and set to child of current stack element. New element is placed on top of element stack. -----------------------------------------------------------------------------
| 961 | // New element is placed on top of element stack. |
| 962 | // ----------------------------------------------------------------------------- |
| 963 | void SimXMLDocument::addNewElement(const char* rName) |
| 964 | { |
| 965 | TiXmlElement cElement( rName ); |
| 966 | TiXmlElement* pStackTop = 0; |
| 967 | if(m_paNode.empty()) |
| 968 | { |
| 969 | pStackTop = dynamic_cast<TiXmlElement*> |
| 970 | (m_qDocument->InsertEndChild( cElement )); |
| 971 | if(!pStackTop) |
| 972 | { |
| 973 | return; |
| 974 | } |
| 975 | m_paNode.push_back(pStackTop); |
| 976 | return; |
| 977 | } |
| 978 | |
| 979 | const S32 iParentElement = m_paNode.size() - 2; |
| 980 | if(iParentElement < 0) |
| 981 | { |
| 982 | pStackTop = dynamic_cast<TiXmlElement*> |
| 983 | (m_qDocument->InsertEndChild( cElement )); |
| 984 | if(!pStackTop) |
| 985 | { |
| 986 | return; |
| 987 | } |
| 988 | m_paNode.push_back(pStackTop); |
| 989 | return; |
| 990 | } |
| 991 | else |
| 992 | { |
| 993 | TiXmlElement* pNode = m_paNode[iParentElement]; |
| 994 | if(!pNode) |
| 995 | { |
| 996 | return; |
| 997 | } |
| 998 | pStackTop = dynamic_cast<TiXmlElement*> |
| 999 | (pNode->InsertEndChild( cElement )); |
| 1000 | if(!pStackTop) |
| 1001 | { |
| 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | // Overwrite top stack position. |
| 1006 | const S32 iFinalElement = m_paNode.size() - 1; |
| 1007 | m_paNode[iFinalElement] = pStackTop; |
| 1008 | //pNode = pStackTop; |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | DefineEngineMethod( SimXMLDocument, addNewElement, void, ( const char* name ),, |
| 1013 | "@brief Create a new element with the given name as child of current Element's " |
no test coverage detected