如何刷新我的xml文档 [英] how to refresh my xml document
问题描述
实际上我将文本字段数据加载到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");
应用程序是一个毫无意义的标记. C#,XML和Winforms怎么样?
cshuhh写道:XmlNode recordnode = node.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"reocord","));
也许您需要RTFM.您追加了一个节点,但是您不想这样做吗?我会使用XmlTextWriter来简化只是覆盖当前文档.然后,我读了一本书,学习了一些东西,而不是在网络上随意复制代码,而当它执行您要的内容而不是您希望的内容时却感到困惑.
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");
Application is a senseless tag. How about C#, XML, Winforms ?
cshuhh wrote:XmlNode recordnode=node.AppendChild(xmldoc.CreateNode(XmlNodeType.Element,"reocord",""));
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文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!