Created
April 22, 2017 07:01
-
-
Save jmcd/0625458f2794789a1d213b9c48b5e409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Xml.Linq; | |
namespace ConsoleApplication1 | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var doc = XDocument.Load(new StringReader(RawXml)); | |
DateTime testDate = new DateTime(2017, 03, 01); | |
var dateElements = doc.Descendants("NewDataSet") | |
// gather all the child-elements of all NewDataSet elements | |
.SelectMany(dataSetEle => dataSetEle.Elements()) | |
// filter out child-elements that themselves have no applicable DATE child-elements | |
.Where(childEle => childEle.Elements() | |
.Any(grandChildEle => | |
grandChildEle.Name == "DATE" && (DateTime) grandChildEle > testDate) | |
); | |
foreach (var dateElement in dateElements) | |
{ | |
Console.WriteLine(dateElement); | |
} | |
Console.WriteLine("PRESS KEY TO END"); | |
Console.ReadKey(); | |
} | |
private static readonly string RawXml = @"<DataSet> | |
<diffgram xmls=""""> | |
<NewDataSet> | |
<USER_LOGIN> | |
<USER_LOGIN_ID>123</USER_LOGIN_ID> | |
<DATE>2017-03-01T16:56:16.59-06:00</DATE> | |
</USER_LOGIN> | |
<CONTENT> | |
<CONTENT_ID>123</CONTENT_ID> | |
<DATE>2017-03-01T16:56:16.59-06:00</DATE> | |
</CONTENT> | |
<SHOULDBEIGNORED> | |
<CONTENT_ID>123</CONTENT_ID> | |
</SHOULDBEIGNORED> | |
<SHOULDBEIGNORED> | |
<CONTENT_ID>123</CONTENT_ID> | |
<DATE>2000-03-01T16:56:16.59-06:00</DATE> | |
</SHOULDBEIGNORED> | |
</NewDataSet> | |
</diffgram> | |
</DataSet>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment