|
|
SAX parsing
Chap4_Ex30.cs
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Collections;
public class Cap4_Ex30_Test {
public static void Main(string[] args) {
XmlTextReader r = new XmlTextReader("organizer.xml");
long sum = 0;
DateTime s , e;
s = new DateTime(2004,1,1,1,1,1);
while (r.Read()) {
if (r.IsStartElement("start")) {
r.Read(); // read the start date
s = DateTime.Parse(r.Value);
}
else if (r.IsStartElement("end")) {
r.Read(); // read the end date
e = DateTime.Parse(r.Value);
TimeSpan ts = e.Subtract(s);
sum += (long)ts.TotalMilliseconds;
}
}
Console.WriteLine("Sum of task durations in ms:{0}", sum);
r.Close();
}
}
|
|