[Dclug] dashboard - an xml based reminder
Johnson, Steve (NIH/OD/ORS) [E]
johnsons at vrp.ncrr.nih.gov
Fri Aug 28 15:36:40 EDT 2009
Everybody must have their system for this, but it is one of the programming tasks I find has to be efficient to be enjoyable -- what with all the editing and updates. But anyhow, and recognizing that this c-sharp code will raise some eyebrows coming as it does from the MS empire (but please realize - c-sharp is an open source project, well, open source if you know how to read C and C++).
So, even realizing I'm not going to get an engineering award for this, I still would like to share a glimpse of how I'm working the reminders program. It dawns on me that more of the querying could be done with the xml itself, rather than running regexs.
What I do is simply edit the xml file, a list of the reminders as so:
<Phrases><Phrase date="Nov-01-2010" track_number = "" amt="" who="anonymous">toner cartridges</Phrase></Phrases>
<Phrases><Phrase date="Nov-01-2010" track_number = "" who="anonymous2">board meeting</Phrase></Phrases>
<Phrases><Phrase date="OCT-30-2009" who="daylights">end DST</Phrase></Phrases>
//code start here
TimeSpan interval = new TimeSpan();
XmlDocument doc = new XmlDocument();
doc.Load(@"\Phrases.xml");
XmlNode root = doc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("//Phrase[@date]");
foreach (XmlNode currentNode in nodeList) {
try {
if ( Regex.IsMatch(currentNode.Attributes["who"].Value, "daylights") ){
holdRemindersString += currentNode.Attributes["who"].Value + "\t\t" + interval.Days + " day\t" +
currentNode.Attributes["date"].InnerText + "\r\n\r\n"; }}
catch {}
finally{}
Obviously that is just a glimpse but the idea is to use node attribute who as a selection criteria. Given that xml as a standard works with dates and numeric values, those string comparisons using regular expressions has got to be a hard way around. Depending on the value of the node attribute (which does not need to maintain order as part of the structure of the xml document) I concatonate all that type reminder and display that string on one screen location; so forth for other category of reminder.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://calypso.tux.org/pipermail/dclug/attachments/20090828/828933e5/attachment-0002.html
More information about the Dclug
mailing list