I am new to LINQ and wanted to write a C# LINQ query to filter nodes on a XDocument Object. How would I filter based on a date Value from within a tag, in this case the tag. I want to loop and create a new XDocument object with the filtered results by Date.
XDocument :
<?xml version="1.0" encoding="UTF-8"?>
<BMW>
<Model>
<Desc>335</Desc>
<ReleaseDate>6/20/2016</ReleaseDate>
<Engine>V6</Engine>
<BodyStyle></BodyStyle>
</Model>
<Model>
<Desc>550</Desc>
<ReleaseDate>7/12/2016</ReleaseDate>
<Engine>V6</Engine>
<BodyStyle></BodyStyle>
</Model>
<Model>
<Desc>750</Desc>
<ReleaseDate>8/26/2016</ReleaseDate>
<Engine>V8</Engine>
<BodyStyle>Executive Sedan</BodyStyle>
</Model>
</BMW>
Here's my method signature
private XDocument FilterByDate(XDocument xDoc, DateTime filterDate)
{
}
My Output :
If I pass the datetime value of 08/26/2016. I should essentially get back a XDocument with the the last ModelTag.
<?xml version="1.0" encoding="UTF-8"?>
<BMW>
<Model>
<Desc>750</Desc>
<ReleaseDate>8/26/2016</ReleaseDate>
<Engine>V8</Engine>
<BodyStyle>Executive Sedan</BodyStyle>
</Model>
</BMW>