Click here to Skip to main content
15,896,429 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
{
    //The class which execute reading of document pare (XML and XSD)
	public class XmlValidatingReader : System.Xml.XmlValidatingReader
	{
		public XmlValidatingReader(System.Xml.XmlReader XmlReader, XmlXsdDocument XmlXsdDocument) : base(XmlReader)
		{
			_parentsStack.Push(XmlXsdDocument);
		}

        /*
        Main part of labor by read and validation of data execute base class.
        Wee just interfere in process in proper time for creation of class which will contain 
        Information about node both from xml file and xsd file.
        */
        public override bool Read()
		{
			if (base.Read())
			{
                //Start to read a node from xml file
				if (this.NodeType == System.Xml.XmlNodeType.Element)
				{
                    //Peek last added element from parent�s stack
					XmlXsdNodeBuilder parentObjectBuilder = (XmlXsdNodeBuilder)_parentsStack.Peek();

                    //Create all omitted child elements (minOccurs = 0 and not presented in xml file) for parent
					parentObjectBuilder.AppendChildsRange(Name);

                    //1)Create next child element for parent
                    //2)Add one to collection of parent�s child
                    //3)Add child element to parents stack
                    _parentsStack.Push(parentObjectBuilder.AppendNextChild(Name));

                    //Empty element <Node/>
					if (this.IsEmptyElement) _fRecElementEmpty = true;
						else _fRecElementEmpty = false;
				}
				else
				{

                    //Stop to read a node from xml file
					if (_fRecElementEmpty || this.NodeType == System.Xml.XmlNodeType.EndElement)
					{
                        //Remove element which end to read from parents stack
						XmlXsdNodeBuilder endElementBuilder = (XmlXsdNodeBuilder)_parentsStack.Pop();

                        //Create all omitted child elements (minOccurs = 0 and not presented in xml file) of one
						endElementBuilder.AppendChildsRange(null);

                        _fRecElementEmpty = false;
					}
						
				}

				return true;
			}
			else
			{
				return false;
			}

		}

		internal XmlXsdNode XmlXsdNode
		{
			get
			{
				return (XmlXsdNode)_parentsStack.Peek();
			}
		}

        //Stack of parent nodes 
		System.Collections.Stack _parentsStack = new System.Collections.Stack();

		bool _fRecElementEmpty = false;

	}
}

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