开发者

C#/LINQ: How to Query this XML Structure

I am trying to get the value of <getthis> but can't seem to get just the string value. I think this is quite simple but I can't seem to get it. I am trying to do it 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 just the value. 开发者_C百科How do I do it?


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


To be sure to get the 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 that's not important Darin's answer is correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜