【问题标题】:Get line number which tag contains text in XML file获取标记包含 XML 文件中文本的行号
【发布时间】:2016-04-04 06:27:02
【问题描述】:

您能告诉我如何使用 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>

【问题讨论】:

标签: c#


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多