Linq to XML query returining a list of strings
- by objectsbinding
Hi all,
I have the following class
public class CountrySpecificPIIEntity
{
public string Country { get; set; }
public string CreditCardType { get; set; }
public String Language { get; set; }
public List<String> PIIData { get; set; }
}
I have the following XML that I want to query using Linq-to-xml and shape in to the class above
<?xml version="1.0" encoding="utf-8" ?>
<piisettings>
<piifilter country="DE" creditcardype="37" language="ALL" >
<filters>
<filter>FIRSTNAME</filter>
<filter>SURNAME</filter>
<filter>STREET</filter>
<filter>ADDITIONALADDRESSINFO</filter>
<filter>ZIP</filter>
<filter>CITY</filter>
<filter>STATE</filter>
<filter>EMAIL</filter>
</filters>
</piifilter>
<piifilter country="DE" creditcardype="37" Language="en" >
<filters>
<filter>EMAIL</filter>
</filters>
</piifilter>
</piisettings>
I'm using the following query but I'm having trouble with the last attribute i.e. PIIList.
var query = from pii in xmlDoc.Descendants("piifilter")
select new CountrySpecificPIIEntity
{
Country = pii.Attribut("country").Value,
CreditCardType = pii.Attribute("creditcardype").Value,
Language = pii.Attribute("Language").Value,
PIIList = (List<string>)pii.Elements("filters")
};
foreach (var entity in query)
{
Debug.Write(entity.Country);
Debug.Write(entity.CreditCardType);
Debug.Write(entity.Language);
Debug.Write(entity.PIIList);
}
How Can I get the query to return a List to be hydrated in to the PIIList property.