2010-10-11 92 views
3

我想获得值<getthis>,但似乎无法得到只是字符串值。我认为这很简单,但我似乎无法得到它。我试图使用LINQC#/ LINQ:如何查询此XML结构

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> 

做到这一点我用

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

,但我只想要值。我该怎么做?

回答

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

就一定要下得信息的获得OS 3.0,我会用以下内容:

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

如果这不是重要的Darin的答案是正确的。