【发布时间】:2016-02-19 11:34:34
【问题描述】:
如何找到xml文件的特定标签的标签和行号, 例如:
<sec id="fm.s2">
<title>Acknowledgments</title>
</sec>
<p>Center for Evidence and Practice Improvement</p>
<p>Agency for Healthcare Research and Quality</p>
<sec id="fm.s2">
<title>Director</title>
</sec>
<p>Center for Evidence and Practice Improvement</p>
<p>Agency for Healthcare Research and Quality</p>
<sec id="fm.s2">
<title>Acknowledgments</title>
</sec>
在此示例中,我想获取 <title> 包含“致谢”文本的行号。
【问题讨论】:
-
逐行读取文件并搜索需要的文本。
-
是的,但我也想要该文本的行号
-
msdn.microsoft.com/en-US/library/… XmlTextReader 类具有 LineNumber 属性。也许你可以找到一种方法来使用这个类来获得你想要的东西。我链接的页面上给出的示例代码看起来已经很接近了。
-
先生,我正在使用 xdocument,所以我想通过 xdocument 输出,所以请给我另一个解决方案
-
stackoverflow.com/questions/4471001/… 已经回答了这个问题。
标签: c# .net xml xml-parsing