Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
XML filtering example
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { string xml = @"<entry> <log_time>20180511-09:06:42</log_time> <description>Authentication succeed</description> <service>COM</service> <sessionid>00000001</sessionid> <type>0</type> <severity>1</severity> <user>username</user> <host>windows</host> <cmd>Login</cmd> </entry>"; // you can use .Load(PATH_TO_FILE) instead var doc = XDocument.Parse(xml); TimeSpan lowerBound = new TimeSpan(8, 0, 0); // change this to new TimeSpan(9, 0, 0); and it won't output your sample entry TimeSpan upperBound = new TimeSpan(10, 0, 0); var filteredElements = doc.Elements("entry").Where(entry => IsInRange(entry, lowerBound, upperBound)); foreach(var element in filteredElements) { Console.WriteLine(element); } } public static bool IsInRange(XElement entry, TimeSpan lowerBound, TimeSpan upperBound) { TimeSpan currentTime = DateTime.ParseExact(entry.Element("log_time").Value, "yyyyMMdd-HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).TimeOfDay; if(lowerBound < currentTime && currentTime < upperBound) { return true; } else { return false; } } } }
run
|
edit
|
history
|
help
0
Get a webpage - the sync way
sdefrgthyjuiujyhtgrf
GetEnumerator
Bubble Sort
Invoke method via reflection
Main4
Binary search tree - In-order Traversal
WithoutPortNo
Math v9.1
StringBuilder