Vishwas Cheluva N
Vishwas Cheluva N

Reputation: 3

Extracting The particular atribute value using other attribute value in c#

Suppose I have the XML file

<?xml version="1.0" ?>
<Tasks>
    <Task>
         <id>1234</id>
         <name>abc</name>
    </Task>

    <Task>
         <id>5678</id>
         <name>xyz</name>
    </Task>
<Tasks>

How can I extract the value of id using the value of name? For example I know the name is abc. How can i extract the value 1234 from the above file?

Upvotes: 1

Views: 64

Answers (1)

Phylogenesis
Phylogenesis

Reputation: 7880

Use the following XPath query to get the id element for a Task with the name of abc:

/Tasks/Task[name='abc']/id

Example of this is here.

Upvotes: 1

Related Questions