我可能只是作弊.:)这将为您提供一个行号和位置:
string s = ""; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); try { doc.LoadXml(s); } catch(System.Xml.XmlException ex) { MessageBox.Show(ex.LineNumber.ToString()); MessageBox.Show(ex.LinePosition.ToString()); } Some text.