Click here to Skip to main content
15,894,907 members
Articles / Programming Languages / XSLT

XmlXsdDocument

Rate me:
Please Sign up or sign in to vote.
4.56/5 (4 votes)
27 Oct 200610 min read 24.5K   568   17  
This article explains the applcation of the XmlXsdDocument class.
using System;

namespace Puma.Xml
{
	public class XmlXsdNodeCollectionFragment : Puma.Collections.Shred
	{
        public XmlXsdNodeCollectionFragment(string Name, Puma.Collections.ShredCollector Container, XsdNode TemplateXsdNode)
            : base(Name, Container)
        {
            _templateXsdNode = TemplateXsdNode;
        }

        private readonly XsdNode _templateXsdNode;

        public XsdNode TemplateXsdNode { get { return _templateXsdNode; } }

        public XmlXsdNode this[int Index] { get { return (XmlXsdNode)base.GetItem(Index); } }

        public XmlXsdNode LastNode { get { return Count == 0 ? null : (XmlXsdNode)GetItem(Count - 1); } }

        public XmlXsdNode InsertXmlXsdNode(int Index)
        {
            System.Diagnostics.Debug.Assert(_templateXsdNode != null);

            if (Index > Count) throw new Puma.Xml.XmlExceptions.ChildCollectionXmlException(Puma.Xml.XmlExceptions.ChildCollectionExceptionCode.NodeIndexInvalid);

            if (Count >= _templateXsdNode.MinMaxOccurs.Max) throw new Puma.Xml.XmlExceptions.ChildCollectionXmlException(Puma.Xml.XmlExceptions.ChildCollectionExceptionCode.MaxOccursLimitExcited);

            XmlXsdNode newNode = new XmlXsdNodeConstructor(GetPervXmlElementInContainer(), _templateXsdNode.XmlSchemaElement, (XmlXsdNode)_templateXsdNode.container.Parent);

            base.Insert(Index, newNode);

            return newNode;
        }

        public XmlXsdNode RemoveXmlXsdNode(int Index)
        {
            XmlXsdNode oldNode = (XmlXsdNode)GetItem(Index);

            System.Diagnostics.Debug.Assert(oldNode.Parent is XmlXsdNode);

            if (Index > Count) throw new Puma.Xml.XmlExceptions.ChildCollectionXmlException(Puma.Xml.XmlExceptions.ChildCollectionExceptionCode.NodeIndexInvalid);

            ((XmlXsdNode)oldNode.Parent).XmlNode.XmlElement.RemoveChild(oldNode.XmlNode.XmlElement);

            base.Remove(Index);

            return oldNode;
        }

        private System.Xml.XmlElement GetPervXmlElementInContainer()
        {
           
            XmlXsdNodeCollectionFragment iterFragment = this;

            while (iterFragment != null)
            {
                if (iterFragment.Count != 0)
                {
                    return iterFragment.LastNode.XmlNode.XmlElement;
                }

                iterFragment = (XmlXsdNodeCollectionFragment)iterFragment.Container.GetPerviousShred(iterFragment.Name);
            }
           
            return null;
        }


        #region Puma.Collections.Shred

        public override bool IsCanInsert
        {
            get
            {
                if (this.Count >= this.TemplateXsdNode.MinMaxOccurs.Max) return false;
                else return true;
            }
        }

        public override bool IsCanRemove
        {
            get
            {
                if (this.Count <= this.TemplateXsdNode.MinMaxOccurs.Min) return false;
                else return true;
            }
        }

        #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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions