我试图使用c#Linq获取子节点数据,我成功获取数据,但不是完美的字符串即时获取数据
例如"<value>data</value>"
像这样,但我想要数据,例如:"data"
这是我获取数据的代码
var format = from data in xml.Descendants("Insurance")
select new
{
Policy = data.Element("CoreDetails").Elements("ReferenceColumn")
.Elements("value")
.Select(x =>x.ToString())
.ToList()
};
XML
<?xml version="1.0" encoding="UTF-8"?>
<Insurance>
<CoreDetails>
<ReferenceColumn type="Array">
<value>Policy number</value>
<value>Address 1</value>
<value>Buidling Prem</value>
</ReferenceColumn>
</CoreDetails>
</Insurance>
答案 0 :(得分:1)
您需要InnerText
或Value
:
var format = from data in xml.Descendants("Insurance")
select new
{
Policy = data.Element("CoreDetails").Elements("ReferenceColumn")
.Elements("value")
.Select(x =>x.InnerText) //.Select(x =>x.Value)
.ToList()
};