从文本框的值保存到XML文档 [英] save values from textbox to xml document
本文介绍了从文本框的值保存到XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要救我的XML格式的网页。我想用XmlDocument的保存价值。我试图寻找,但我无法找到保存在一个文本框输入到XML文档数据的正确方法。
有什么办法?虽然不正确,但是这是我做了什么至今。
XDOC XmlDocument的=新的XmlDocument();
//创建根节点。
的XmlElement XElemRoot = XDoc.CreateElement(Generate_License); //节点添加到文档中。
XDoc.AppendChild(XElemRoot);
的XmlElement Xsource = XDoc.CreateElement(General_Info,txtGInfo.ToString());
XElemRoot.AppendChild(Xsource);
解决方案
您可以尝试 - 以的InnerText
属性
//创建XML文档containe
XmlDocument的DOC =新的XmlDocument(); //创建XML声明,并将其附加到XML文档
XmlDeclaration DEC = doc.CreateXmlDeclaration(1.0,NULL,NULL);
doc.AppendChild(DEC); //创建根元素XmlElement的根= doc.CreateElement(Generate_License);的XmlElement ELEM = doc.CreateElement(General_Info);
elem.InnerText = txtGInfo.Text;root.AppendChild(ELEM);
doc.AppendChild(根);
I want to save my webpage in XML format. I thought of using XmlDocument to save the values. I tried searching it but I couldn't find a proper way for saving the data entered in a textbox to the xml document.
Is there any way? Although incorrect, but this is what I've done till now.
XmlDocument XDoc = new XmlDocument();
// Create root node.
XmlElement XElemRoot = XDoc.CreateElement("Generate_License");
//Add the node to the document.
XDoc.AppendChild(XElemRoot);
XmlElement Xsource = XDoc.CreateElement("General_Info", txtGInfo.ToString());
XElemRoot.AppendChild(Xsource);
解决方案
You can try with - based on InnerText
property
// Create the xml document containe
XmlDocument doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
doc.AppendChild(dec);// Create the root element
XmlElement root = doc.CreateElement("Generate_License");
XmlElement elem= doc.CreateElement("General_Info");
elem.InnerText =txtGInfo.Text;
root.AppendChild(elem);
doc.AppendChild(root);
这篇关于从文本框的值保存到XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文