Given an XML file like:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Policy id="832cbfc6-a451-4d77-a995-4ceb9d3bbe01" username ="DCassidy">
<Title>Test 1</Title>
</Policy>
<Policy id="832cbfc6-a451-4d77-a995-4ceb9d3bbe02" userName ="DCassidy">
<Title>Test 2</Title>
</Policy>........and so on
Is it possible to use LINQ to XML to return all the 'Policy' elements and their containing elements without having to specify each element thing like:
var subset = doc.Elements("Policy").SelectMany(x => new[] { x.Element("Title").Value });
I need to be able to dynamically add elements to the file, filter and return a subset.
preferabbly, returning a collection of XElemets so that later I can call:
subset.CreateReader() on.
EDIT
To be clearer. I will want to return ALL Policy objects and their descendants based on the username attribute. I the want to take that subset and use CreateReader() on it.
Can someone help please?
Thanks