"Multiple" XML-File (new input should not replace) using c# -
i'm writing short program displays me do's. got 2 tabs. 1 tab create new , other tab displaying me details of every selected. have save created do's in xml file. using datatable
, dataset
, works fine. here code:
datatable datatable = new datatable(); datatable.tablename = "saveinput"; datacolumn dc1 = new datacolumn("name"); datacolumn dc2 = new datacolumn("priority"); datacolumn dc3 = new datacolumn("startdate"); datacolumn dc4 = new datacolumn("enddatesoll"); datacolumn dc5 = new datacolumn("enddateist"); datacolumn dc6 = new datacolumn("comment"); datatable.columns.add(dc1); datatable.columns.add(dc2); datatable.columns.add(dc3); datatable.columns.add(dc4); datatable.columns.add(dc5); datatable.columns.add(dc6); datatable.rows.add(txt_name.text, combox_priority.text, txt_beginn.text, txt_endsoll.text, txt_endist.text, txt_bemerkungen.text); dataset dataset = new dataset(); dataset.tables.add(datatable); dataset.datasetname = "myprogram"; dataset.writexml(@"c:\users\rs\desktop\test\save.xml");
but problem is: if create new "to do" in tab1, replace new "to do" in .xml file. if have @ .xml file, there still 1 "to do". want write more tables in .xml file. .xml file looks this:
<myprogram> <saveinput> <name>todo1</name> <priority>high</priority> <startdate>today</startdate> <enddatesoll>later</enddatesoll> <enddateist>not finished</enddateist> <comment>blabla</comment> </saveinput> </myprogram>
but should example:
<myprogram> <saveinput> <name>todo1</name> <priority>high</priority> <startdate>today</startdate> <enddatesoll>later</enddatesoll> <enddateist>not finished</enddateist> <comment>blabla</comment> <name>todo2</name> <priority>high</priority> <startdate>yesterday</startdate> <enddatesoll>tomorrow</enddatesoll> <enddateist>not finished</enddateist> <comment>testtest</comment> </saveinput> </myprogram>
i hope can me or give me hint can create more 1 to-do.
cheers
edit: it's winform application
this code should work you.
check out
dataset ds = new dataset(); if (file.exists(@"c:\users\rs\desktop\test\save.xml")) { ds.readxml(@"c:\users\rs\desktop\test\save.xml"); ds.tables[0].rows.add(txt_name.text, combox_priority.text, txt_beginn.text, txt_endsoll.text, txt_endist.text, txt_bemerkungen.text); ds.writexml(@"c:\users\rs\desktop\test\save.xml"); } else { datatable datatable = new datatable(); datatable.tablename = "saveinput"; datacolumn dc1 = new datacolumn("name"); datacolumn dc2 = new datacolumn("priority"); datacolumn dc3 = new datacolumn("startdate"); datacolumn dc4 = new datacolumn("enddatesoll"); datacolumn dc5 = new datacolumn("enddateist"); datacolumn dc6 = new datacolumn("comment"); datatable.columns.add(dc1); datatable.columns.add(dc2); datatable.columns.add(dc3); datatable.columns.add(dc4); datatable.columns.add(dc5); datatable.columns.add(dc6); datatable.rows.add(txt_name.text, combox_priority.text, txt_beginn.text, txt_endsoll.text, txt_endist.text, txt_bemerkungen.text); dataset dataset = new dataset(); dataset.tables.add(datatable); dataset.datasetname = "myprogram"; dataset.writexml(@"c:\users\rs\desktop\test\save.xml"); }
Comments
Post a Comment