/** @brief Load all Application settings in one shot from the XML file.
* @remarks CoInitialize() or CoInitializeEx() must have been called before using this method.
* @param _sFileName the full path name of an existing file
*/
bool MenuCommandSetCfg::_LoadFile(const std::string& _sFileName)
{
	const _bstr_t XMLDOM_OBJECT= _T("Microsoft.XMLDOM");
	const _bstr_t NODE_DART(_T("uicfg"));
	const _bstr_t NODE_COMMANDS(_T("commands"));
	const _bstr_t NODE_VERSION(_T("version"));
	const _bstr_t NODE_COMMANDLIST(_T("commandlist"));
	const _bstr_t NODE_MENULIST(_T("menulist"));

	bool bResult= false;

	try
	{
		MSXML::IXMLDOMDocumentPtr XMLDom;
		HRESULT hResult = XMLDom.CreateInstance((LPCSTR)XMLDOM_OBJECT);
		if(S_OK==hResult)
		{
			_ClearLists();

			_bstr_t FileName(_sFileName.c_str());

			if(XMLDom->load(FileName))
			{
				MSXML::IXMLDOMNodePtr Root= XMLDom->selectSingleNode(NODE_DART);
				MSXML::IXMLDOMNodePtr XMLNode;
				MSXML::IXMLDOMNodePtr XMLNode2;
				if( Root != NULL )
				{
					//load the file version
					XMLNode = Root->selectSingleNode(NODE_VERSION);
					_LoadFileVersion(XMLNode);

					//load the list of menu items
					XMLNode = Root->selectSingleNode(NODE_COMMANDS);
					if(XMLNode){
						XMLNode2= XMLNode->selectSingleNode(NODE_COMMANDLIST);
						_LoadMenuItemList(XMLNode2);

						XMLNode2= XMLNode->selectSingleNode(NODE_MENULIST);
						_LoadMenuList(XMLNode2);
					}
					bResult= true;
				}
			}
		}
		else{
			TRACE(_T("Failed to load XMLDom (%x)\n"), hResult);
		}
	}
	catch(...){
		TRACE(_T("Exception while loading config file\n"));
	}
	return bResult;
}
////////////////////////////////////////////////////////////////////////////
// Helper function: Walk all the Elements at a particular node
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::WalkTree(int iLevel, MSXML::IXMLDOMNode* pNode)
{
	HRESULT hr = S_OK;

	CComBSTR bstrNodeName;
	pNode->get_nodeName(&bstrNodeName);

	CComVariant vNodeValue;
	pNode->get_nodeValue(&vNodeValue);
	vNodeValue.ChangeType(VT_BSTR);
	CString strValueString = V_BSTR(&vNodeValue);

	if (m_pCallbackFunction)
		m_pCallbackFunction(iLevel, CString(bstrNodeName), strValueString, m_pCallbackParam);

	MSXML::IXMLDOMNamedNodeMapPtr pAttributes = NULL;
	if (SUCCEEDED(pNode->get_attributes(&pAttributes)) && (pAttributes != NULL))
	{
		MSXML::IXMLDOMNodePtr pAttribute = NULL;
		pAttributes->nextNode(&pAttribute);
		while (pAttribute)
		{
			CComBSTR bstrNodeName;
			pAttribute->get_nodeName(&bstrNodeName);

			CComVariant vNodeValue;
			pAttribute->get_nodeValue(&vNodeValue);
			vNodeValue.ChangeType(VT_BSTR);
			CString strValueString = V_BSTR(&vNodeValue);

			if (m_pCallbackFunction)
				m_pCallbackFunction(iLevel+1, CString(bstrNodeName), strValueString, m_pCallbackParam);

			pAttributes->nextNode(&pAttribute);
		}
	}

	MSXML::IXMLDOMNodePtr pChild = NULL;
	pNode->get_firstChild(&pChild);
	while (pChild)
	{
		WalkTree(iLevel+1, pChild);

		MSXML::IXMLDOMNode* pNext = NULL;
		pChild->get_nextSibling(&pNext);
		pChild = pNext;
	}

	return S_OK;
}
////////////////////////////////////////////////////////////////////////////
// Function: Create an XML DOM Document from Scratch in memory
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::Build()
{
	// Create a root node
	MSXML::IXMLDOMNodePtr pRoot;
	m_pDoc->createNode(CComVariant(MSXML::NODE_ELEMENT), CComBSTR("Root"), NULL, &pRoot);

	// add child nodes
	HRESULT hr = S_OK;
	for (int i = 0; i < 10; i++)
	{
		MSXML::IXMLDOMNodePtr pNode;
		m_pDoc->createNode(CComVariant(MSXML::NODE_ELEMENT), CComBSTR("Order"), NULL, &pNode);

		MSXML::IXMLDOMElementPtr pElement = pNode;
		if (pElement != NULL)
			pElement->setAttribute(CComBSTR("id"), CComVariant(i));

		MSXML::IXMLDOMNodePtr p0 = NULL;
		CComVariant after;
		hr = pRoot->insertBefore(pNode, after, &p0);
		hr = CheckHR(hr, "inserting node");

		// The XML Document should now own the node.
		for (int j = 0; j < 10; j++)
		{
			MSXML::IXMLDOMNodePtr pNode2;
			m_pDoc->createNode(CComVariant(MSXML::NODE_ELEMENT), CComBSTR("Item"), NULL, &pNode2);

			MSXML::IXMLDOMElementPtr pElement2 = pNode2;
			if (pElement2 != NULL)
				pElement2->setAttribute(CComBSTR("id"), CComVariant((i*10) + j));
	
			MSXML::IXMLDOMNodePtr p1 = NULL;
			CComVariant after;
			hr = p0->insertBefore(pNode2, after, &p1);
			hr = CheckHR(hr, "inserting node");
			// The XML Document should now own the node.
		}
	}

	// Now attach this new subtree to the document.
	m_pDoc->appendChild(pRoot, NULL);

	return hr;
}
Exemple #4
0
bool CHelpDB::GetItemElement(CTSTRING& _sAlias, MSXML::IXMLDOMElementPtr& Out, bool bCreate)
{
    bool r = false;
    TSTRING sXPath;
    MSXML::IXMLDOMNodePtr Node;
    TSTRING sAlias;

    {
        TCHAR* tsz = _tcsdup(_sAlias.c_str());
        _tcsupr(tsz);
        sAlias = tsz;
        SAFE_FREE(tsz);
    }

    // this will look something like MSG[@ALIAS="hithere"]
    sprintf(sXPath, TAG_MSG _T("[@") TAG_ALIAS _T("=\"%s\"]"), sAlias.c_str());

    try
    {
        Node = m_root->selectSingleNode(_bstr_t(sXPath.c_str()));

        if((Node == NULL) && (bCreate == true))
        {
            MSXML::IXMLDOMElementPtr NewEl;
            MSXML::IXMLDOMNodePtr NewNode;

            NewEl = m_doc->createElement("MSG");
            NewEl.QueryInterface(__uuidof(MSXML::IXMLDOMNode), &NewNode);
            Node = m_root->appendChild(NewNode);
        }

        if(Node != NULL)
        {
            Node.QueryInterface(__uuidof(MSXML::IXMLDOMElement), &Out);
            r = true;
        }
    }
    catch(_com_error& e)
    {
        sprintf(m_err, _T("COM Error: %08x"), e.Error());
        g_pLog->msg(_T("CHelpDB::GetItemElement(%s)"), _sAlias.c_str());
    }

    return r;
}
Exemple #5
0
bool CHelpDB::DeleteItem(CTSTRING& sAlias)
{
    MSXML::IXMLDOMElementPtr El;
    MSXML::IXMLDOMNodePtr Node;
    MSXML::IXMLDOMNodePtr Parent;
    bool r = false;
    if(m_doc == 0) return false;

    if(GetItemElement(sAlias, El, false))
    {
        El.QueryInterface(__uuidof(MSXML::IXMLDOMNode), &Node);
        Parent = Node->GetparentNode();
        Parent->removeChild(Node);
        r = true;
    }

    return r;
}
Exemple #6
0
CString GetXmlValue(MSXML::IXMLDOMNodeListPtr pNodeList, char* key, int pos)
{
	try{
		if(pNodeList==NULL)
			return "";
		MSXML::IXMLDOMNodePtr pSubNode;
		pSubNode = pNodeList->item[pos]->selectSingleNode(key);
		if(pSubNode==NULL)
			return "";
		_bstr_t strRequestType = pSubNode->Gettext();
		CString res;
		res.Format("%s",(char*)strRequestType);
		pSubNode.Release();
		return res;
	}
	catch(_com_error &e){
#ifdef _DEBUG
		AfxMessageBox(e.ErrorMessage());
#endif
		return "";
	}
}
Exemple #7
0
void CXMLArchive::ResetMainPos()
{
#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;
		CXMLArchiveNode* xmlNodePtr = m_nodeList.top();
		xmlNodePtr->m_childIndex = 0;
	}

	fatherNodePtr->ResetMainPos();
}
Exemple #8
0
bool CMessageEnum::Next(CHelpMessage& nfo)
{
    bool r = false;
    MSXML::IXMLDOMNodePtr Node;
    MSXML::IXMLDOMElementPtr Element;

    try
    {
        Node = m_list->nextNode();
        Node.QueryInterface(__uuidof(MSXML::IXMLDOMElement), &Element);

        r = m_pOwner->ElementToStruct(nfo, Element);
    }
    catch(_com_error&)
    {
        g_pLog->msg(_T("CMessageEnum::Next COM ERROR"));
    }
    catch(...)
    {
    }

    return r;
}
Exemple #9
0
bool CHelpDB::Open(TSTRING& sFileName)
{
    HRESULT hr = 0;
    bool r = false;
    Close();

    g_pLog->msg(_T("Attempting to open %s"), sFileName.c_str());

    try
    {
        if(SUCCEEDED(m_doc.CreateInstance("Msxml.DOMDocument")))
        {
            if(VARIANT_TRUE == m_doc->load(_variant_t(sFileName.c_str())))
            {
                m_sFileName = sFileName;

                // Get the top level node for later use.
                MSXML::IXMLDOMNodePtr Root;

                if(FAILED(hr = m_doc.QueryInterface(__uuidof(MSXML::IXMLDOMNode), &Root)))
                {
                    throw _com_error(hr);
                }

                try
                {
                    m_root = Root->selectSingleNode(_bstr_t(_T("/") TAG_HELPMSGS));

                    if(m_root != 0)
                    {
                        r = true;
                    }
                }
                catch(_com_error& e)
                {
                    sprintf(m_err, _T("COM Error: %08x"), e.Error());
                }
            }
            else
            {
                // Deal with an error from m_doc->load().
                MSXML::IXMLDOMParseErrorPtr pParse = m_doc->parseError;
                try
                {
                    if(pParse != 0)
                    {
                        TSTRING sReason, sText, sURL;
                        long lErrCode = pParse->errorCode;
                        long lFilePos = pParse->filepos;
                        long lLine = pParse->line;
                        long lCol = pParse->linepos;
                        if(pParse->reason.length()) HW2T(sReason, (BSTR)(pParse->reason));
                        if(pParse->srcText.length()) HW2T(sText, (BSTR)(pParse->srcText));
                        if(pParse->url.length()) HW2T(sURL, (BSTR)(pParse->url));

                        // Format the error.
                        sprintf(m_err, _T("Parsing Error #%d [%s] (line %d, col %d, filepos: %d, url %s, text: %s)"),
                            lErrCode, sReason.c_str(), lLine, lCol, lFilePos, sURL.c_str(), sText.c_str());
                        g_pLog->msg(_T("%s"), m_err.c_str());
                    }
                }
                catch(_com_error& e)
                {
                    TSTRING s = e.Description();
                    sprintf(m_err, _T("COM Error: %08x: %s"), e.Error(), s.c_str());
                    g_pLog->msg(_T("%s"), m_err.c_str());
                }
            }
        }
    }
    catch(_com_error& e)
    {
        sprintf(m_err, _T("COM Error: %08x"), e.Error());
        g_pLog->msg(_T("%s"), m_err.c_str());
    }

    if(!r)
    {
        // free up stuff.
        g_pLog->msg(_T("Failed to open %s"), sFileName.c_str());
        Close();
    }
    else
    {
        g_pLog->msg(_T("Successfully opened %s"), sFileName.c_str());
    }

    return r;
}
Exemple #10
0
bool NZBFile::ParseNZB(IUnknown* nzb)
{
	MSXML::IXMLDOMDocumentPtr doc = nzb;
	MSXML::IXMLDOMNodePtr root = doc->documentElement;

	MSXML::IXMLDOMNodePtr node = root->selectSingleNode("/nzb/head/meta[@type='password']");
	if (node)
	{
		_bstr_t password(node->Gettext());
		m_szPassword = strdup(password);
	}

	MSXML::IXMLDOMNodeListPtr fileList = root->selectNodes("/nzb/file");
	for (int i = 0; i < fileList->Getlength(); i++)
	{
		node = fileList->Getitem(i);
		MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("subject");
		if (!attribute) return false;
		_bstr_t subject(attribute->Gettext());
        FileInfo* pFileInfo = new FileInfo();
		pFileInfo->SetSubject(subject);

		attribute = node->Getattributes()->getNamedItem("date");
		if (attribute)
		{
			_bstr_t date(attribute->Gettext());
			pFileInfo->SetTime(atoi(date));
		}

		MSXML::IXMLDOMNodeListPtr groupList = node->selectNodes("groups/group");
		for (int g = 0; g < groupList->Getlength(); g++)
		{
			MSXML::IXMLDOMNodePtr node = groupList->Getitem(g);
			_bstr_t group = node->Gettext();
			pFileInfo->GetGroups()->push_back(strdup((const char*)group));
		}

		MSXML::IXMLDOMNodeListPtr segmentList = node->selectNodes("segments/segment");
		for (int g = 0; g < segmentList->Getlength(); g++)
		{
			MSXML::IXMLDOMNodePtr node = segmentList->Getitem(g);
			_bstr_t id = node->Gettext();
            char szId[2048];
            snprintf(szId, 2048, "<%s>", (const char*)id);

			MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("number");
			if (!attribute) return false;
			_bstr_t number(attribute->Gettext());

			attribute = node->Getattributes()->getNamedItem("bytes");
			if (!attribute) return false;
			_bstr_t bytes(attribute->Gettext());

			int partNumber = atoi(number);
			int lsize = atoi(bytes);

			if (partNumber > 0)
			{
				ArticleInfo* pArticle = new ArticleInfo();
				pArticle->SetPartNumber(partNumber);
				pArticle->SetMessageID(szId);
				pArticle->SetSize(lsize);
				AddArticle(pFileInfo, pArticle);
			}
		}

		AddFileInfo(pFileInfo);
	}
	return true;
}
Exemple #11
0
	HRESULT getParamsFromXMLConfigFile(short mode, std::wstring * appexe, std::wstring * params)
	{
		::CoInitialize(NULL);
		MSXML::IXMLDOMDocumentPtr m_plDomDocument;
		MSXML::IXMLDOMElementPtr m_pDocRoot;

		HRESULT hr = m_plDomDocument.CreateInstance(MSXML::CLSID_DOMDocument);
		if (hr==S_OK)
		{		
			_bstr_t bstrFileName = _T("JavaService.xml");
			variant_t vResult;
			vResult = m_plDomDocument->load(bstrFileName);
			if (((bool)vResult) == TRUE) // success!
			{
				if (mode==STARTUP)
				{
					// now that the document is loaded, we need to initialize the root pointer
					m_pDocRoot = m_plDomDocument->documentElement;
					MSXML::IXMLDOMNodePtr jdkRoot = m_pDocRoot->selectSingleNode("//startup/jdk/javahome");
					MSXML::IXMLDOMNodePtr jvmmode = m_pDocRoot->selectSingleNode("//startup/jdk/jvmmode");
					MSXML::IXMLDOMNodePtr jvmclasspath = m_pDocRoot->selectSingleNode("//startup/jdk/classpath");
					MSXML::IXMLDOMNodePtr endorsedpath = m_pDocRoot->selectSingleNode("//startup/jdk/endorsedpath");				
					MSXML::IXMLDOMNodePtr syshost = m_pDocRoot->selectSingleNode("//startup/jdk/syshost");
					MSXML::IXMLDOMNodePtr minheap = m_pDocRoot->selectSingleNode("//startup/jdk/initmemory");
					MSXML::IXMLDOMNodePtr maxheap = m_pDocRoot->selectSingleNode("//startup/jdk/maxmemory");
					MSXML::IXMLDOMNodePtr newsize = m_pDocRoot->selectSingleNode("//startup/jdk/NewSize");
					MSXML::IXMLDOMNodePtr maxnewsize = m_pDocRoot->selectSingleNode("//startup/jdk/MaxNewSize");
					MSXML::IXMLDOMNodePtr survivorratio = m_pDocRoot->selectSingleNode("//startup/jdk/survivorratio");				
					MSXML::IXMLDOMNodePtr permsize = m_pDocRoot->selectSingleNode("//startup/jdk/permsize");
					MSXML::IXMLDOMNodePtr gcInterval = m_pDocRoot->selectSingleNode("//startup/jdk/gcInterval");
					MSXML::IXMLDOMNodePtr threadstacksize = m_pDocRoot->selectSingleNode("//startup/jdk/threadstacksize");
					MSXML::IXMLDOMNodePtr progname = m_pDocRoot->selectSingleNode("//startup/app/progname");				
					MSXML::IXMLDOMNodePtr appclass = m_pDocRoot->selectSingleNode("//startup/app/class");
					MSXML::IXMLDOMNodePtr classrunparams = m_pDocRoot->selectSingleNode("//startup/app/classrunparams");
					MSXML::IXMLDOMNodePtr extrajvmparams = m_pDocRoot->selectSingleNode("//startup/app/extrajvmparams");


					BSTR bjdkRoot;
					hr = jdkRoot->get_text(&bjdkRoot); 
					if (hr==S_OK) 
					{
						*appexe = _bstr_t(bjdkRoot) + _T("\\java.exe");

						BSTR bjvmmode;				
						BSTR bjvmclasspath;
						BSTR bendorsedpath;
						BSTR bsyshost;
						BSTR bminheap;
						BSTR bmaxheap;
						BSTR bnewsize;
						BSTR bmaxnewsize;
						BSTR bsurvivorratio;
						BSTR bpermsize;
						BSTR bgcInterval;
						BSTR bthreadstacksize;
						BSTR bprogname;
						BSTR bappclass;
						BSTR bclassrunparams;
						BSTR bextrajvmparams;

						hr = jvmmode->get_text(&bjvmmode) & 
							jvmclasspath->get_text(&bjvmclasspath) & 
							endorsedpath->get_text(&bendorsedpath) &
							syshost->get_text(&bsyshost) & 
							minheap->get_text(&bminheap) & 
							maxheap->get_text(&bmaxheap) & 
							newsize->get_text(&bnewsize) & 
							maxnewsize->get_text(&bmaxnewsize) & 
							survivorratio->get_text(&bsurvivorratio) &
							permsize->get_text(&bpermsize) & 
							gcInterval->get_text(&bgcInterval) &
							threadstacksize->get_text(&bthreadstacksize) &
							progname->get_text(&bprogname) & 
							appclass->get_text(&bappclass) & 
							classrunparams->get_text(&bclassrunparams) &
							extrajvmparams->get_text(&bextrajvmparams);  
						if (hr==S_OK)
						{		
							*params = _T("-") + _bstr_t(bjvmmode) + _T(" -Dprogram.name=") + _bstr_t(bprogname) 
								+ _T(" -Dsys.host=") + _bstr_t(bsyshost)
								+ _T(" -Xms") + _bstr_t(bminheap) + _T(" -Xmx") + _bstr_t(bmaxheap) 
								+ _T(" -XX:NewSize=") + _bstr_t(bnewsize) + _T(" -XX:MaxNewSize=") + _bstr_t(bmaxnewsize) 
								+ _T(" -XX:SurvivorRatio=") + _bstr_t(bsurvivorratio) 
								+ _T(" -XX:MaxPermSize=") + _bstr_t(bpermsize) 
								+ _T(" -Xss") + _bstr_t(bthreadstacksize)
								+ _T(" -Dsun.rmi.dgc.server.gcInterval=") + _bstr_t(bgcInterval) 
								+ _T(" -Djava.endorsed.dirs=") + _bstr_t(bendorsedpath) 
								+ _T(" ") + _bstr_t(bextrajvmparams) 
								+ _T(" -classpath ") + _bstr_t(bjvmclasspath) 
								+ _T(" ") + _bstr_t(bappclass)
								+ _T(" ") + _bstr_t(bclassrunparams);
						} else {
							LogEvent(_T("Failed to load application params from configuration file"));
						}
					} else {
						LogEvent(_T("Failed to load JDK setting from configuration file"));
					}
				} else {
					// Mode must be STOPPING. Now that the document is loaded, we need to initialize the root pointer
					m_pDocRoot = m_plDomDocument->documentElement;
					MSXML::IXMLDOMNodePtr jdkRoot = m_pDocRoot->selectSingleNode("//shutdown/jdk/javahome");
					
					MSXML::IXMLDOMNodePtr jvmclasspath = m_pDocRoot->selectSingleNode("//shutdown/jdk/classpath");
					MSXML::IXMLDOMNodePtr progname = m_pDocRoot->selectSingleNode("//shutdown/app/progname");				
					MSXML::IXMLDOMNodePtr appclass = m_pDocRoot->selectSingleNode("//shutdown/app/class");					
					MSXML::IXMLDOMNodePtr extrajvmparams = m_pDocRoot->selectSingleNode("//shutdown/app/extrajvmparams");

					BSTR bjdkRoot;
					hr = jdkRoot->get_text(&bjdkRoot); 
					if (hr==S_OK) 
					{
						*appexe = _bstr_t(bjdkRoot) + _T("\\java.exe");

						
						BSTR bjvmclasspath;						
						BSTR bprogname;
						BSTR bappclass;						
						BSTR bextrajvmparams;

						hr = jvmclasspath->get_text(&bjvmclasspath) & 							
							progname->get_text(&bprogname) & 							
							extrajvmparams->get_text(&bextrajvmparams) &
							appclass->get_text(&bappclass);  
						if (hr==S_OK)
						{		
							*params = _T(" -Dprogram.name=") + _bstr_t(bprogname) 								
								+ _T(" ") + _bstr_t(bextrajvmparams) 
								+ _T(" -classpath ") + _bstr_t(bjvmclasspath) 								
								+ _T(" ") + _bstr_t(bappclass);
								
						} else {
							LogEvent(_T("Failed to load application params from configuration file"));
						}
					} else {
						LogEvent(_T("Failed to load JDK setting from configuration file"));
					}
				}
			}
			else
			{
				LogEvent(_T("Failed to load configuration file"));
				return E_FAIL;
			}
		} else {
			LogEvent(_T("Failed to MSXML library."));
		}

		return hr;
	}
Exemple #12
0
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;
}