获取标记包含XML文件中的文本的行号

时间:2016-04-04 06:27:03

标签: c#

您能告诉我如何使用XDocument或XmlDocument获取行号吗?

在XDocument中,

输入:

1. <title-group>
2. <article-title>Education Finance: How It Differs from the and the 
Analytic and Data Collection    Changes It Implies</article-title>
4. </title-group>
5. <contrib-group>
6. <contrib contrib-type="author"><name><surname>Guthrie</surname><given-names>James W.</given-names></name><aff>Department of Leadership, Policy and Organization, Peabody College of Vanderbil University, 230 Appleton Place, @ Nashville, TN 37203-5721, E-mail: <email xlink="jwgxiii@sbcglobal.net">jwgxiii@sbcglobal.net</email></aff>
7. testest</contrib>
8. </contrib-group>

我的输出如下:

2. <article-title>Education Finance: How It Differs from the and the Analytic and Data Collection    Changes It Implies</article-title>
6. <contrib contrib-type="author"><name><surname>Guthrie</surname><given-names>James W.</given-names></name><aff>Department of Leadership, Policy and Organization, Peabody College of Vanderbil University, 230 Appleton Place, @ Nashville, TN 37203-5721, E-mail: <email xlink="jwgxiii@sbcglobal.net">jwgxiii@sbcglobal.net</email></aff>
7. testest</contrib>

1 个答案:

答案 0 :(得分:1)

如果XDocument支持线路信息,则需要check using the HasLineInfo method。 如果是,您可以通过IXmlLineInfo Interface使用LineNumber property等功能。