本文介绍了如何刷新我的xml文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我将文本字段数据加载到xml文件中
但是当我下次执行程序时,它将把我的文本字段数据附加到我不想要的xml文件中.我希望下次xml存储新数据时,不要将该数据附加到以前的数据中

我的代码是:-

XmlDocument xmldoc =新的XmlDocument();
xmldoc.Load(@"E:\\ grabone1 \\ grabone1 \\ Insert.xml");
XmlNode节点= xmldoc.SelectSingleNode("records");
XmlNode recordnode = node.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"reocord",")));
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"tlpl06m",")).InnerText = txttplm.Text;
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"tlpl06f",")).InnerText = txttplf.Text;
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"tlpl06",")).InnerText = txttpltotal.Text;
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"catagory",")).InnerText = txtcatgory.Text;

xmldoc.Save(@"E:\\ grabone1 \\ grabone1 \\ Insert.xml");

解决方案


actually i load my text field data into a xml file
but when i execute my programe next time it will append my text field data into xml file which i dont want .i want that next time xml store new data not append that data in to previous data

my code is:-

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"E:\\grabone1\\grabone1\\Insert.xml");
XmlNode node = xmldoc.SelectSingleNode("records");
XmlNode recordnode=node.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"reocord",""));
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element, "tlpl06m", "")).InnerText = txttplm.Text;
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element, "tlpl06f", "")).InnerText = txttplf.Text;
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element, "tlpl06", "")).InnerText = txttpltotal.Text;
recordnode.AppendChild(xmldoc.CreateNode(XmlNodeType.Element, "catagory", "")).InnerText = txtcatgory.Text;

xmldoc.Save(@"E:\\grabone1\\grabone1\\Insert.xml");

解决方案



Perhaps you need to RTFM. You append a node, but you don''t want to do that ? I''d use an XmlTextWriter to simplify just overwriting your current document. Then I''d read a book and learn something instead of copying code at random over the web and getting confused when it does what you ask it, instead of what you hoped it might.


这篇关于如何刷新我的xml文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 17:27