user6254141
user6254141

Reputation: 21

I want to fetch the data of child node from XML using C# Linq

im trying to get child node data using c# Linq and i successfully fetch the data but not perfect string im getting data eg "<value>data</value>" like this but i want data eg: "data"

this my code to fetch the 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>

Upvotes: 0

Views: 83

Answers (1)

Romano Zumb&#233;
Romano Zumb&#233;

Reputation: 8099

You need the InnerText or 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()
             };

Upvotes: 1

Related Questions