find line number of specific tag of xml file [duplicate]

You can do it with linq

var xml = XDocument.Load(@"path", LoadOptions.SetLineInfo);

var lineNumbers = xml.Descendants()
            .Where(x =>!x.Descendants().Any() && //exact node contains the value
                        x.Value.Contains("Acknowledgments"))
            .Cast<IXmlLineInfo>()
            .Select(x => x.LineNumber);

Leave a Comment