Click here to Skip to main content
10,500,000 members (69,589 online)
Click here to Skip to main content

Stats

21.8K views
434 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
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace Elmax
{
    /// <summary>
    /// Class to access XML CData Section
    /// </summary>
    public class CData
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public CData()
        {
            _CData = null;
        }
        /// <summary>
        /// Non-default Constructor
        /// </summary>
        /// <param name="cdata">XmlCDataSection to initialize from</param>
        public CData(XmlCDataSection cdata)
        {
            _CData = cdata;
        }

        /// <summary>
        /// Accessor for the content
        /// </summary>
        public string Content
        {
            get
            {
                return GetContent();
            }
        }

        /// <summary>
        /// Accessor for the length of the content
        /// </summary>
        public long Length
        {
            get
            {
                return GetLength();
            }
        }

        /// <summary>
        /// Accessor to determine if the CData Section is valid
        /// </summary>
        public bool Valid
        {
            get
            {
                return IsValid();
            }
        }

        /// <summary>
        /// Get the CDataSection data
        /// </summary>
        /// <returns>CData Section contents</returns>
        public string GetContent()
        {
	        if(_CData==null)
                throw new System.InvalidOperationException("Invalid CData object");

	        return _CData.Data;
        }
        /// <summary>
        /// Get the length of the CDataSection content in Char size (2 bytes)
        /// </summary>
        /// <returns></returns>
        public long GetLength()
        {
	        if(_CData==null)
                throw new System.InvalidOperationException("Invalid CData object");

	        return _CData.Length;
        }
        /// <summary>
        /// Delete itself
        /// </summary>
        /// <returns>true if successful</returns>
        public bool Delete()
        {
	        if(_CData==null)
                throw new System.InvalidOperationException("Invalid CData object");

	        XmlNode parent = _CData.ParentNode;
	        if(parent!=null)
	        {
		        _CData = (XmlCDataSection)(parent.RemoveChild(_CData));
	        }
	        else
		        return false;

	        return true;
        }

        /// <summary>
        /// Update the CData section contents
        /// </summary>
        /// <param name="data"></param>
        /// <returns>true if successful</returns>
        public bool Update(string data)
        {
	        if(_CData==null)
                throw new System.InvalidOperationException("Invalid CData object");

	        _CData.ReplaceData(0, data.Length, data);
	        return true;
        }
        /// <summary>
        /// Get internal XmlCDataSection object
        /// </summary>
        /// <returns>Internal XmlCDataSection object</returns>
        public XmlCDataSection GetInternalObject()
        {
            return _CData;
        }
        /// <summary>
        /// Check if CData Section is valid
        /// </summary>
        /// <returns>true if valid</returns>
        public bool IsValid()
        {
            if (_CData == null)
                return false;

            return true;
        }
        /// <summary>
        /// Internal XmlCDataSection object
        /// </summary>
        private XmlCDataSection _CData;

    }
}

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)
United States United States
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.160621.1 | Last Updated 12 Apr 2016
Article Copyright 2016 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid