protected bool ProcessStatement(XmlElement element, IXmlProcessorEngine engine)
		{
			if (!element.HasAttribute(DefinedAttrName) &&
				!element.HasAttribute(NotDefinedAttrName))
			{
				throw new XmlProcessorException("'if' elements expects a non empty defined or not-defined attribute");
			}

			if (element.HasAttribute(DefinedAttrName) &&
				element.HasAttribute(NotDefinedAttrName))
			{
				throw new XmlProcessorException("'if' elements expects a non empty defined or not-defined attribute");
			}

			bool processContents = false;

			if (element.HasAttribute(DefinedAttrName))
			{
				processContents = engine.HasFlag(element.GetAttribute(DefinedAttrName));
			}
			else
			{
				processContents = !engine.HasFlag(element.GetAttribute(NotDefinedAttrName));
			}

			return processContents;
		}
        protected bool ProcessStatement(XmlElement element, IXmlProcessorEngine engine)
        {
            if (!element.HasAttribute(DefinedAttrName) &&
                !element.HasAttribute(NotDefinedAttrName))
            {
                throw new XmlProcessorException("'if' elements expects a non empty defined or not-defined attribute");
            }

            if (element.HasAttribute(DefinedAttrName) &&
                element.HasAttribute(NotDefinedAttrName))
            {
                throw new XmlProcessorException("'if' elements expects a non empty defined or not-defined attribute");
            }

            bool processContents = false;

            if (element.HasAttribute(DefinedAttrName))
            {
                processContents = engine.HasFlag(element.GetAttribute(DefinedAttrName));
            }
            else
            {
                processContents = !engine.HasFlag(element.GetAttribute(NotDefinedAttrName));
            }

            return(processContents);
        }
        private void ProcessElseElement(XmlProcessingInstruction pi, IXmlProcessorEngine engine, ref StatementState state)
        {
            AssertData(pi, pi.Name == ElsifPiName);

            if (state == StatementState.Collect)
            {
                state = StatementState.Finished;
            }
            else if (pi.Name == ElsePiName || engine.HasFlag(pi.Data))
            {
                if (state == StatementState.Init)
                {
                    state = StatementState.Collect;
                }
            }

            RemoveItSelf(pi);
            return;
        }
        public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine)
        {
            XmlProcessingInstruction node = nodeList.Current as XmlProcessingInstruction;

            AssertData(node, true);

            StatementState state = engine.HasFlag(node.Data) ? StatementState.Collect : StatementState.Init;

            List <XmlNode> nodesToProcess = new List <XmlNode>();
            int            nestedLevels   = 0;

            RemoveItSelf(nodeList.Current);

            while (nodeList.MoveNext())
            {
                if (nodeList.Current.NodeType == XmlNodeType.ProcessingInstruction)
                {
                    XmlProcessingInstruction pi = nodeList.Current as XmlProcessingInstruction;

                    if (pi.Name == EndPiName)
                    {
                        nestedLevels--;

                        if (nestedLevels < 0)
                        {
                            RemoveItSelf(nodeList.Current);
                            break;
                        }
                    }
                    else if (pi.Name == IfPiName)
                    {
                        nestedLevels++;
                    }
                    else if (nestedLevels == 0)
                    {
                        if (pi.Name == ElsePiName || pi.Name == ElsifPiName)
                        {
                            ProcessElseElement(pi, engine, ref state);
                            continue;
                        }
                    }
                }

                if (state == StatementState.Collect)
                {
                    nodesToProcess.Add(nodeList.Current);
                }
                else
                {
                    RemoveItSelf(nodeList.Current);
                }
            }

            if (nestedLevels != -1)
            {
                throw new XmlProcessorException("Unbalanced pi if element");
            }

            if (nodesToProcess.Count > 0)
            {
                engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(nodesToProcess));
            }
        }
		public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine)
		{
			XmlProcessingInstruction node = nodeList.Current as XmlProcessingInstruction;

			AssertData(node, true);

			StatementState state = engine.HasFlag(node.Data) ? StatementState.Collect : StatementState.Init;

            List<XmlNode> nodesToProcess = new List<XmlNode>();
			int nestedLevels = 0;

			RemoveItSelf(nodeList.Current);

			while(nodeList.MoveNext())
			{
				if (nodeList.Current.NodeType == XmlNodeType.ProcessingInstruction)
				{
					XmlProcessingInstruction pi = nodeList.Current as XmlProcessingInstruction;

					if (pi.Name == EndPiName)
					{
						nestedLevels--;

						if (nestedLevels < 0)
						{
							RemoveItSelf(nodeList.Current);
							break;
						}
					}
					else if (pi.Name == IfPiName)
					{
						nestedLevels++;
					}
					else if (nestedLevels == 0)
					{
						if (pi.Name == ElsePiName || pi.Name == ElsifPiName)
						{
							ProcessElseElement(pi, engine, ref state);
							continue;
						}
					}
				}

				if (state == StatementState.Collect)
				{
					nodesToProcess.Add(nodeList.Current);
				}
				else
				{
					RemoveItSelf(nodeList.Current);
				}
			}

			if (nestedLevels != -1)
			{
				throw new XmlProcessorException("Unbalanced pi if element");
			}

			if (nodesToProcess.Count > 0)
			{
				engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(nodesToProcess));
			}
		}
		private void ProcessElseElement(XmlProcessingInstruction pi, IXmlProcessorEngine engine, ref StatementState state)
		{
			AssertData(pi, pi.Name == ElsifPiName);

			if (state == StatementState.Collect)
			{
				state = StatementState.Finished;
			}
			else if (pi.Name == ElsePiName || engine.HasFlag(pi.Data))
			{
				if (state == StatementState.Init)
				{
					state = StatementState.Collect;
				}
			}

			RemoveItSelf(pi);
			return;
		}