从文本框的值保存到XML文档

编程入门 行业动态 更新时间:2024-10-28 20:21:44
本文介绍了从文本框的值保存到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文档containeXmlDocument的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文档

本文发布于:2023-11-09 09:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   文档   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!