C # / LINQ: how to query this XML structure

I am trying to get the value <getthis>, but it seems that only the string value cannot get. I think it is quite simple, but I can not understand. I am trying to do this with LINQ

XML

<?xml version="1.0" encoding="utf-8"?>
<root>
    <item>
        <name></name>
        <title></title>
    </item>
    <info>
        <getthis>value here</getthis>
        <something>another value</something>
    </info>
</upload>

I used

var link = from links in doc.Descendants("getthis")
           select links;

but I want only value. How to do it?

+3
source share
2 answers
var link = from links in doc.Descendants("getthis")
           select links.Value;
+4
source

To get getthis under info, I would use the following:

var result = from info in xd.Descendants("info")
             from getthis in xd.Descendants("getthis")
             select getthis.Value;

If it doesn’t matter, Darin’s answer is correct.

0
source

Source: https://habr.com/ru/post/1768943/


All Articles