Find Next XML Element In Sequence - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Find Next XML Element In Sequence

Demo Code


using System.Xml;
using System.Collections.Generic;
using System;/*  w  w w.  j a v a  2s  . co  m*/

public class Main{
        public static bool FindNextElementInSequence(XmlReader reader, string name, string nameSpace, Comparison<string> comparison)
      {
         while (FindNextElementInSequence(reader, name, comparison))
         {
            if (reader.NamespaceURI == nameSpace)
            {
               return true;
            }
            reader.Skip();
         }
         return false;
      }
        public static bool FindNextElementInSequence(XmlReader reader, string name, Comparison<string> comparison)
      {
         while (!reader.EOF && reader.NodeType != XmlNodeType.EndElement &&
            (reader.NodeType != XmlNodeType.Element || comparison(name, reader.Name) > 0))
         {
            switch (reader.NodeType)
            {
               case XmlNodeType.Attribute:
               case XmlNodeType.Element:
                  reader.Skip();
                  break;
               default:
                  reader.Read();
                  break;
            }
         }
         int result = comparison(name, reader.Name);
         return !reader.EOF && reader.NodeType == XmlNodeType.Element && name == reader.Name;
      }
}

Related Tutorials