I have xml file and I want to find line number of the specific tag from their value without its attribute and its parent tag.
For example, I have address tag on line number 321 and I want to find that line number using linq <address>Example1</address>
even without its parent tag and xml file don't have any attribute..
This code is giving me exception that there is no element.
var lineNumbers = xml.Descendants("ChildTag")
.Where(x =>!x.Descendants().Any() && //exact node contains the value
x.Value.Contains("value inside child tag"))
.Cast<IXmlLineInfo>()
.Select(x => x.LineNumber);
I have checked all the solutions on stack overflow but nothing is working perfectly. Here acknowledgment is the value here.
Note: I want to match with the value inside that tag and get the line number of it.
Sample XML File
<DocumentDetails>
<WitnessInfo>
<SROCode>342</SROCode>
<WitnessID>2324</WitnessID>
<DocumentID>158932420</DocumentID>
<Name>ExampleName</Name>
<Address>Address</Address>
<Age>23</Age>
<Profession />
<PhoneNo />
<IsOnline>false</IsOnline>
</WitnessInfo>
<PartyWitness>
<SROCode>2342</SROCode>
<PartyID>34234223</PartyID>
<WitnessID>342</WitnessID>
<WitnessDate>2022-10-03T11:59:52</WitnessDate>
</PartyWitness>
</DocumentDetails>
Here I have this xml file and there is an address tag over there where I am getting line number 321 from the exception and I wan to find the parent tag of it. But before finding the parent tag I want to go to that line number 321 to matched with the line number which I got from the exception. That's my question. How I can fetch it..