ritz
ritz

Reputation: 29

Get line number which tag contains text in XML file

Can you please tell me how to get line number using XDocument or XmlDocument?

In XDocument,

Input:

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="[email protected]">[email protected]</email></aff>
7. testest</contrib>
8. </contrib-group>

My output will look like:

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="[email protected]">[email protected]</email></aff>
7. testest</contrib>

Upvotes: 1

Views: 110

Answers (1)

TyrantsBeard
TyrantsBeard

Reputation: 73

You will need to check using the HasLineInfo method if the XDocument supports line information. If it does you can use it via the IXmlLineInfo Interface for functions like the LineNumber property.

Upvotes: 1

Related Questions