xml's IndexOf method - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

xml's IndexOf method

Demo Code


using System.Xml;

public class Main{
        #endregion/*from   w ww  .ja v a  2 s.  c  o  m*/

        /// <summary>
        /// xml's IndexOf method
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static int FindElementIndex(XmlNode node)
        {
            int index = 0;
            foreach (XmlNode n in node.ParentNode.ChildNodes)
            {
                if (n.NodeType == XmlNodeType.Comment)
                    continue;
                if (n == node)
                    return index;
                index++;
            }

            return -1;
        }
}

Related Tutorials