//doc = XDocument.Load(f); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(f.Substring(f.IndexOf(Environment.NewLine))); // Error In this line. var node = xmldoc.SelectSingleNode("//DOCTYPE"); if (node != null) { }