/// <summary> /// Gets the number of children of a section, at a certain depth. Default is depth = 1 /// </summary> /// <param name="reader"></param> /// <param name="stream"></param> /// <returns></returns> public static int GetNumOfChildrenOfSection(this XmlReader reader, int maxDepth = 1) { var xmlReaderClone = reader.CreateClone(); var c = 0; var name = xmlReaderClone.Name; var line = xmlReaderClone.Value; var depth = xmlReaderClone.Depth; while (xmlReaderClone.Read() && !(xmlReaderClone.NodeType == XmlNodeType.EndElement && xmlReaderClone.Name == name)) { if (xmlReaderClone.Depth == depth + maxDepth && xmlReaderClone.NodeType != XmlNodeType.EndElement) { c++; } } return(c); }