c# - Read XML to dictionary -
i know question have been asked multiple times, have not manage solve problem despite trying several suggestions other similar questions.
now ask instead, in hope answer.
i have xml file:
<?xml version="1.0" encoding="utf-8"?> <webcommands> <webcommand> <fullcommand>@ 05c9fe42-8d89-401d-a9a5-2d82af58e16f test webcommands!</fullcommand> <timestamp>18.06.2015 02:56:22</timestamp> </webcommand> </webcommands>
i need fullcommand , timestamp added dictionary
dictionary<datetime, string> commands = new dictionary<datetime, string>();
how i:
1. add fullcommand , timestamp dictionary?
2. convert timestamp string proper datetime?
- add fullcommand , timestamp dictionary?
var commands = new dictionary<datetime, string>(); xdocument xdoc = xdocument.load("filename.xml"); foreach (xelement xcommand in xdoc.root.elements()) { commands.add( datetime.parse(xcommand.element("timestamp").value, cultureinfo.currentculture), xcommand.element("fullcommand").value); }
- convert timestamp string proper datetime
datetime.parse(xcommand.element("timestamp").value, cultureinfo.currentculture)
parsing datetime
culture specific operation. make sure use correct culture in case cultureinfo.currentculture
isn't viable.
Comments
Post a Comment