如何找到在C#中的行和列数的XML节点? [英] How to find an XML node from a line and column number in C#?
本文介绍了如何找到在C#中的行和列数的XML节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 行号
- 列号
- 的XML文件
(凡行和列数所代表的'<'节点的字符)
使用的XDocument API如何找到该位置的XNode。
解决方案
您可以做这样的事情:
XNode FindNode(字符串路径,诠释行,诠释列)
{
的XDocument DOC = XDocument.Load(路径,LoadOptions.SetLineInfo);
VAR的查询=从节点
在doc.DescendantNodes()
让lineInfo =(IXmlLineInfo)节点
,其中lineInfo.LineNumber ==线
和;&安培; lineInfo.LinePosition< =列
选择节点;
返回query.LastOrDefault();
}
Given the following
- A line number
- A column number
- An XML file
(Where the line and column number represent the '<' character of a node)
Using the XDocument API how do I find the XNode at that position.
解决方案
You can do something like that:
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();
}
这篇关于如何找到在C#中的行和列数的XML节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文