我有xml:
<?xml version="1.0" encoding="utf-8" ?>
<books>
<book>
<author>Ray</author>
<album>Other</album>
<cover size="large">LargeCover</cover>
<cover size="mini">MiniCover</cover>
</book>
</books>
如何获取字符串“MiniCover”?
我写了代码,但它不起作用——字符串为空;
string testLink = (@"Text.xml");
XDocument xml = XDocument.Load(testLink);
string cv = String.Empty;
var c = from cover in xml.Elements("book")
where (string)cover.Attribute("size").Value == "mini"
select cover.Value;
foreach (var item in c)
{
cv += item.ToString();
}
MessageBox.Show(cv);
谢谢!