0
我正在學習linq。我有一個的XElement像下面從xelement獲取值
<Customer>
<Orders>
<param id="13" title="Book1" />
<param id="15" title="Book2" />
</Orders>
<Customer/>
如何獲得id的值作爲一個逗號分隔的字符串
我正在學習linq。我有一個的XElement像下面從xelement獲取值
<Customer>
<Orders>
<param id="13" title="Book1" />
<param id="15" title="Book2" />
</Orders>
<Customer/>
如何獲得id的值作爲一個逗號分隔的字符串
XElement xe = XElement.Parse(xmlString);
var ids =
String
.Join
(
",",
xe
.Elements("Orders")
.Elements("param")
.Select(x=>x.Attribute("id").Value)
.ToArray()
);
var ids = XElement.Load(xmlString)
.Descendants("param")
.Select(e => e.Attribute("id").Value);
var result = String.Join(",", ids);