CXMLArchiveNode* CXMLArchive::GetNode(LPCTSTR nodeNameStr) { CString nodeName(nodeNameStr); try { #ifdef USE_MSXML BSTR nodeNameBSTR = nodeName.AllocSysString(); MSXML::IXMLDOMNodePtr fatherNodePtr; #else CMarkup* fatherNodePtr; #endif if (m_nodeList.size() == 0) { fatherNodePtr = m_xmlDocPtr; } else { fatherNodePtr = m_nodeList.top()->m_nodePtr; } if (fatherNodePtr == NULL) { return NULL; } if (IsStoring()) { #ifdef USE_MSXML // Archive is storing CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, m_xmlDocPtr->createElement(nodeNameBSTR), fatherNodePtr); ::SysFreeString(nodeNameBSTR); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; #endif // Archive is storing m_xmlDocPtr->AddChildElem(nodeName); CMarkup* childnodep = new CMarkup(m_xmlDocPtr->GetDoc()); childnodep = m_xmlDocPtr; m_xmlDocPtr->ResetChildPos(); CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, childnodep, //m_xmlDocPtr->createElement(nodeNameBSTR), fatherNodePtr); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; } // Archive is Loading //MSXML::IXMLDOMNodeListPtr nodeListPtr; //MSXML::IXMLDOMNodePtr nodePtr; CMarkup* nodeListPtr; CMarkup* nodePtr; // If child node list is not empty, we are loading using the tags to // create CObject derived objects or collections (like CArray<Cobject* CObject*>, use child list #ifdef USE_MSXML if (m_nodeList.size() > 0) { CXMLArchiveNode* xmlNodePtr = m_nodeList.top(); nodeListPtr = xmlNodePtr->m_childNodeListPtr; if (nodeListPtr != NULL && nodeListPtr->length > 0) { int childIndex = xmlNodePtr->m_childIndex; if (childIndex < nodeListPtr->length) { nodeListPtr->get_item(childIndex, &nodePtr); CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, nodePtr, m_xmlDocPtr); m_nodeList.push(xmlArchiveNodePtr); ::SysFreeString(nodeNameBSTR); return xmlArchiveNodePtr; } ASSERT(FALSE); } } #else if (m_nodeList.size() > 0) { CXMLArchiveNode* xmlNodePtr = m_nodeList.top(); nodeListPtr = xmlNodePtr->m_childNodeListPtr; //Block added to calcule length when using CMarkup int length = 0; if (nodeListPtr != NULL){ nodeListPtr->ResetMainPos(); while (nodeListPtr->FindElem()) { length++; } nodeListPtr->ResetMainPos(); } if (nodeListPtr != NULL && length > 0) { int childIndex = xmlNodePtr->m_childIndex; if (childIndex < length) { int index = 0; /*if (nodeListPtr->FindChildElem()) {*/ while (nodeListPtr->FindElem() && index < childIndex) { index++; } nodePtr = new CMarkup(); nodePtr = nodeListPtr; //nodeListPtr->ResetChildPos(); /*}*/ CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, nodePtr, m_xmlDocPtr); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; } ASSERT(FALSE); } } #endif #ifdef USE_MSXML // Get all nodes with this name if (MSXML::IXMLDOMDocumentPtr(fatherNodePtr) != NULL) { // First level node in document ASSERT(!nodeName.IsEmpty()); nodeListPtr = MSXML::IXMLDOMDocumentPtr(fatherNodePtr)->getElementsByTagName(nodeNameBSTR); } else { // Get node with desired name nodeListPtr = MSXML::IXMLDOMElementPtr(fatherNodePtr)->getElementsByTagName(nodeNameBSTR); } ::SysFreeString(nodeNameBSTR); #else bool bResult=fatherNodePtr->FindElem(nodeName); nodeListPtr = new CMarkup(); nodeListPtr = fatherNodePtr; #endif //Get child index from m_nodeList int childIndex = 0; if (m_nodeList.size() > 0) { childIndex = m_nodeList.top()->m_childIndex; } #ifdef USE_MSXML if (childIndex < nodeListPtr->length) { nodeListPtr->get_item(childIndex, &nodePtr); } #else //Block added to calcule length when using CMarkup int length = 0; nodeListPtr->ResetMainPos(); while (nodeListPtr->FindElem()) { length++; } nodeListPtr->ResetMainPos(); if (childIndex < length) { int index = 0; //Check if it has child elements and go inside if so if (nodeName.MakeLower()=="svg" && nodeListPtr->FindChildElem()) { while (index < childIndex && nodeListPtr->FindElem()) { index++; } nodeListPtr->IntoElem(); nodePtr = new CMarkup(); nodePtr = nodeListPtr; nodeListPtr->ResetMainPos(); } else { while (index < childIndex && nodeListPtr->FindElem(nodeName)) { index++; } nodePtr = new CMarkup(); nodePtr = nodeListPtr; } } #endif CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, nodePtr, m_xmlDocPtr); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; } catch (...) { } return NULL; }