XDocument xdoc = XDocument.Load(file); IEnumerable<XElement> categories = xdoc.Descendants("Category"); foreach (XElement category in categories) { //get line number for element here... }
XDocument xdoc = XDocument.Load(file, LoadOptions.SetLineInfo); IEnumerable<XElement> categories = xdoc.Descendants("Category"); foreach (XElement category in categories) { //get line number for element here... string lineNumber = ((IXmlLineInfo)category).HasLineInfo() ? ((IXmlLineInfo)category).LineNumber : -1; }