Hi,
I have an XML string that looks like this:
<Attributes>
<ProductAttribute id="1">
<ProductAttributeValue>
<Value>a</Value>
</ProductAttributeValue>
</ProductAttribute>
<ProductAttribute id="2">
<ProductAttributeValue>
<Value>a</Value>
</ProductAttributeValue>
<ProductAttributeValue>
<Value>b</Value>
</ProductAttributeValue>
</ProductAttribute>
</Attributes>
I would like to return an IEnumerable like this:
Id Value
1 a
2 a b
I have tried this and only got the "b" value for Id "2":
XElement e = XElement.Parse(xmlString);
var q = from pa in e.Elements("ProductAttribute")
from pav in pa.Elements("ProductAttributeValue").Elements("Value")
select new
{
Id = (int)pa.Attribute("id"),
Value = (string)pav
};
I tried this:
XElement e = XElement.Parse(xmlString);
var q = from pa in e.Elements("ProductAttribute")
select new
{
Id = (int)pa.Attribute("id"),
Value = pa.Elements("ProductAttributeValue").Elements("Value")
};
But could not cast Value as a string. Using LINQPad the output was like this:
Id Value
1 a
2 <Value>a</Value>
<Value>b</Value>
I am trying to just return the values. Is this even possible?
Thanks.