Sim*_*mon 5 c# xml linq-to-xml
鉴于以下情况
(其中行号和列号代表节点的“<”字符)
使用 XDocument API 如何找到该位置的 XNode。
你可以这样做:
XNode FindNode(string path, int line, int column)
{
XDocument doc = XDocument.Load(path, LoadOptions.SetLineInfo);
var query =
from node in doc.DescendantNodes()
let lineInfo = (IXmlLineInfo)node
where lineInfo.LineNumber == line
&& lineInfo.LinePosition <= column
select node;
return query.LastOrDefault();
}
Run Code Online (Sandbox Code Playgroud)