Click here to Skip to main content
12,300,021 members (52,955 online)
Click here to Skip to main content

Stats

21.6K views
431 downloads
27 bookmarked
Posted

Linq-To-XML Style of Node Creation for C++

, 12 Apr 2016 Ms-PL
Linq-To-XML Node Creation for Native C++
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Tryout
res
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
TryoutNet
Properties
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
#include "StdAfx.h"
#include "NewTreeNode.h"

using namespace Elmax;

NewTreeNode::NewTreeNode(void)
{
	pName = L"";
	pValue = L"";

	xmltype = XML_NONE;
}


NewTreeNode::~NewTreeNode(void)
{
}

void NewTreeNode::Delete()
{
	for(size_t i=0;i<vec.size();++i)
		vec.at(i)->Delete();

	vec.clear();
	delete this;
}

bool NewTreeNode::Traverse(MSXML2::IXMLDOMDocumentPtr& ptrDoc,  MSXML2::IXMLDOMNodePtr& parent, NewTreeNode* pNode)
{
	if(!ptrDoc||!parent)
		return false;

	if(pNode==NULL)
		return false;

	for(size_t i=0;i<pNode->vec.size();++i)
	{
		NewTreeNode* pNode1 = pNode->vec.at(i);

		if(pNode1->xmltype==XML_ELEMENT)
		{
			_bstr_t str(pNode1->pName.c_str());
			_variant_t varType(MSXML2::NODE_ELEMENT);
			_bstr_t emptyUri(L"");
			MSXML2::IXMLDOMNodePtr elem = ptrDoc->createNode(varType, str, emptyUri);
			parent->appendChild(elem);
			if(pNode1->pValue!=L"")
				elem->Puttext(_bstr_t(pNode1->pValue.c_str()));

			bool b = Traverse(ptrDoc, elem, pNode1);
			if(b==false)
				return false;
		}
		else if(pNode1->xmltype==XML_COMMENT)
		{
			MSXML2::IXMLDOMNodePtr domComment = ptrDoc->createNode(MSXML2::NODE_COMMENT, _bstr_t(pNode1->pName.c_str()), L"");

			if(!domComment)
				return false;

			domComment->Puttext(pNode1->pValue.c_str());

			parent->appendChild(domComment);
		}
		else if(pNode1->xmltype==XML_CDATA)
		{
			MSXML2::IXMLDOMNodePtr domCData = ptrDoc->createNode(MSXML2::NODE_CDATA_SECTION, _bstr_t(pNode1->pValue.c_str()), L"");

			if(!domCData)
				return false;

			domCData->nodeValue = bstr_t(pNode1->pValue.c_str());

			parent->appendChild(domCData);
		}
		else if(pNode1->xmltype==XML_ATTRIBUTE)
		{
			MSXML2::IXMLDOMNamedNodeMapPtr attrList = parent->Getattributes();

			if(!attrList)
				return false;

			MSXML2::IXMLDOMAttributePtr pAttr = ptrDoc->createAttribute(_bstr_t(pNode1->pName.c_str()));

			if(attrList&&pAttr)
			{
				pAttr->Puttext(_bstr_t(pNode1->pValue.c_str()));
				attrList->setNamedItem(pAttr);
			}
		}
	}
	return true;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Shao Voon Wong
Software Developer (Senior)
Singapore Singapore
IT Certifications

  • IT Infrastructure Library Foundational (ITIL v3)
  • Scrum Alliance Certified Scrum Master (CSM)
  • EC-Council Certified Secure Programmer (ECSP) .NET
  • EC-Council Certified Ethical Hacker (CEH)
  • EC-Council Certified Security Analyst (ECSA)
  • Certified Secure Software Lifecycle Professional (CSSLP)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 12 Apr 2016
Article Copyright 2016 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid