假设在我的C#代码中,我从一个XmlDocument(或XDocument)中检索到了一个XmlElement(或XElement)。我该如何获取这个XmlElement在XML文件中的字符位置?
换句话说,我想知道:
"Your element starts on the 176th character in the text file containing the XML",
不是
"Your 'book' element is the 3rd 'book' element in the whole XML document".
var document = XDocument.Load(fileName, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
- Beauty