Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

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

, 7 Jun 2012
Linq-To-XML Node Creation for Native C++
elmax-84498.zip
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
Settings.settings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
elmax-ver083.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver084.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver085.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver086.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver087.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089.zip
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
Settings.settings
ElmaxSrcVer082.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
// RootElement.h - Addition for the Elmax XML library
//
// Declares the RootElement class that is derived from the Element class.
// This class manages the connection between XML DOM and the xml file.
// It is intended to be used only as the root of the XML DOM
//
// written by: PJ Arends
// Modified by: Wong Shao Voon
// License: Ms-PL

#pragma once

#include "Element.h"
#include "Document.h"

namespace Elmax
{

	class RootElement : public Element
	{
	private:
		//! XML Document pointer
		//MSXML2::IXMLDOMDocumentPtr m_pDoc;
		//! File path name for the XML document
		std::wstring m_FilePath;

	protected:
		//! Can the file be written to?
		//!
		//! @param FilePath - the fully qualified file and path name for the file
		//! @param OverWrite - true if the existing file can be overwritten
		//! @param CreateFolder - true to create the folders if they are not already there
		//! returns - true if the file can be written to
		bool CanWriteFile(const std::wstring& FilePath, bool OverWrite, bool CreateFolder);

	public:
		//ctors
		//! Default ctor
		//! Loads the supplied file if it exists
		//! creates an empty XML DOM if it does not
		RootElement(const std::wstring& FilePath = L"") { LoadFile(FilePath); }

		//! Copy ctor
		RootElement(const Elmax::RootElement &other) { *this = other; }

		//! dtor
		virtual ~RootElement();

		//! Assignment operator
		RootElement& operator = (const RootElement &other);

		//! equality operator: true if both objects point to the same XML document
		//!                    object even if the file names are different
		bool operator == (const RootElement &other) { return m_ptrDoc == other.m_ptrDoc; }

		//! Load a XML file: return true if successful
		bool LoadFile(const std::wstring& FilePath = L"");

		//! Check if a file is loaded into the object
		bool IsFileLoaded() { return NULL != m_ptrDoc; }

		//! Unload the file from memory - it is NOT saved first
		bool UnloadFile();

		//! Get the path to the XML file
		std::wstring GetFilePath() { return m_FilePath; }

		//! Set a new path for the XML file, returns false if no document is currently loaded
		bool SetFilePath(std::wstring FilePath);

		//! Save the file, specify a new path to change the files name and/or location
		//!
		//! @param FilePath - the fully qualified file and path name for the file
		//! @param OverWrite - true if the existing file can be overwritten
		//! @param CreateFolder - true to create the folders if they are not already there
		//! returns - true if the file was successfully saved
		//!
		bool SaveFile(const std::wstring& FilePath = L"", bool OverWrite = true, bool CreateFolder = false);

	private:
		bool FileExists(const std::wstring& fileName);
		bool FolderExists(const std::wstring& Path);

		std::wstring GetFolder(const std::wstring& FilePath);
		bool CreateDirectory(const std::wstring& dd);

	};

} //namespace Elmax

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
Singapore Singapore
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid