Click here to Skip to main content
15,894,405 members
Articles / Programming Languages / XML

Xmlawy XML Framework

Rate me:
Please Sign up or sign in to vote.
4.94/5 (20 votes)
29 Dec 2008CPOL2 min read 30.3K   268   35  
An object based framework to access XML files
// <copyright file="BaseDataObject.cs" company="islameldemery.blogspot.com/">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Islam Eldemery</author>
// <email>issy.sam@gmail.com</email>
// <date>2008-12-29</date>
// <summary>The base class that represents an xml node</summary>

namespace Xmlawy
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The base class that represents an xml node
    /// </summary>
    public class BaseDataObject : InterfaceDataObject
    {
        #region Feilds
        /// <summary>
        /// The node name
        /// </summary>
        private string name = string.Empty;

        /// <summary>
        /// The node value
        /// </summary>
        private string value = string.Empty;

        /// <summary>
        /// The node attributes
        /// </summary>
        private List<XmlAttribute> attributes = new List<XmlAttribute>();

        /// <summary>
        /// The node childs
        /// </summary>
        private List<BaseDataObject> childs = new List<BaseDataObject>();
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        public BaseDataObject()
        {
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        public BaseDataObject(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="value">The node value</param>
        public BaseDataObject(string name, string value)
        {
            this.name = name;
            this.value = value;
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="value">The node value</param>
        /// <param name="attributes">List of node attributes</param>
        public BaseDataObject(string name, string value, params XmlAttribute[] attributes)
        {
            this.name = name;
            this.value = value;

            for (int i = 0; i < attributes.Length; i++)
            {
                this.attributes.Add(attributes[i]);
            }
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="value">The node value</param>
        /// <param name="attributes">List of node attributes</param>
        public BaseDataObject(string name, string value, List<XmlAttribute> attributes)
        {
            this.name = name;
            this.value = value;
            this.attributes = attributes;
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="childs">List of childs</param>
        public BaseDataObject(string name, params BaseDataObject[] childs)
        {
            this.name = name;

            for (int i = 0; i < childs.Length; i++)
            {
                this.childs.Add(childs[i]);
            }
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="childs">List of childs</param>
        public BaseDataObject(string name, List<BaseDataObject> childs)
        {
            this.name = name;
            this.childs = childs;
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="childs">List of childs</param>
        /// <param name="attributes">List of attributes</param>
        public BaseDataObject(string name, List<BaseDataObject> childs, params XmlAttribute[] attributes)
        {
            this.name = name;
            this.childs = childs;

            for (int i = 0; i < attributes.Length; i++)
            {
                this.attributes.Add(attributes[i]);
            }
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="childs">List of childs</param>
        /// <param name="attributes">List of attributes</param>
        public BaseDataObject(string name, List<BaseDataObject> childs, List<XmlAttribute> attributes)
        {
            this.name = name;
            this.childs = childs;
            this.attributes = attributes;
        }

        /// <summary>
        /// Initializes a new instance of the BaseDataObject class
        /// </summary>
        /// <param name="name">The node name</param>
        /// <param name="attributes">List of attributes</param>
        /// <param name="childs">List of childs</param>
        public BaseDataObject(string name, List<XmlAttribute> attributes, params BaseDataObject[] childs)
        {
            this.name = name;
            this.attributes = attributes;

            for (int i = 0; i < childs.Length; i++)
            {
                this.childs.Add(childs[i]);
            }
        }
        #endregion

        #region InterfaceDataObject Properties
        /// <summary>
        /// Gets or sets a value of the node name
        /// </summary>
        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.name = value;
            }
        }
        
        /// <summary>
        /// Gets or sets a value of the node value
        /// </summary>
        public string Value
        {
            get
            {
                return this.value;
            }

            set
            {
                this.value = value;
            }
        }

        /// <summary>
        /// Gets or sets a value of the list of the node attributes
        /// </summary>
        public List<XmlAttribute> Attributes
        {
            get
            {
                return this.attributes;
            }

            set
            {
                this.attributes = value;
            }
        }

        /// <summary>
        /// Gets or sets a value of the list of the node childs
        /// If u set childs, the value will be ignored
        /// </summary>
        public List<BaseDataObject> Childs
        {
            get
            {
                return this.childs;
            }

            set
            {
                if (this.value != null)
                {
                    this.value = null;
                }

                this.childs = value;
            }
        }
        #endregion
    }
}

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 Code Project Open License (CPOL)


Written By
Web Developer Business Development Gate
Egypt Egypt

Comments and Discussions