C# 将值从文本框保存到xml文档

C# 将值从文本框保存到xml文档,c#,asp.net,xml,textbox,xmldocument,C#,Asp.net,Xml,Textbox,Xmldocument,我想以XML格式保存我的网页。我考虑使用XmlDocument保存这些值。我尝试搜索它,但找不到将文本框中输入的数据保存到xml文档的正确方法 有办法吗?虽然不正确,但这是我到现在为止所做的 XmlDocument XDoc = new XmlDocument(); // Create root node. XmlElement XElemRoot = XDoc.CreateElement("Generate_License"); //Ad

我想以XML格式保存我的网页。我考虑使用XmlDocument保存这些值。我尝试搜索它,但找不到将文本框中输入的数据保存到xml文档的正确方法

有办法吗?虽然不正确,但这是我到现在为止所做的

 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);

您可以尝试使用-based
InnerText
属性

// 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);

您可以尝试使用-based
InnerText
属性

// 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);

试试这个,这很简单。只是您需要4.0.NETFramework

XDocument doc =
  new XDocument(
    new XElement("Generate_License",
      new XElement("General_Info", txtGInfo.ToString())

      )
    )
  );

试试这个,这很简单。只是您需要4.0.NETFramework

XDocument doc =
  new XDocument(
    new XElement("Generate_License",
      new XElement("General_Info", txtGInfo.ToString())

      )
    )
  );

请给出一个输入的数据和预期的XML文件的例子好吗?在“常规信息”中输入的数据是字母数字的,没有特定的XML格式。应该有某种格式,您将保存数据…因此,如果您想在文件中保存字符串,为什么要使用XML?一个简单的文本文件是不够的?它不仅仅是字符串。这只是第一个元素。我有一个包含下拉列表的正确网页,单选按钮和文本字段。请给出输入的数据和预期的XML文件的示例。在“常规信息”中输入的数据是字母数字的,没有XML的特定格式。应该有某种格式可以保存数据…因此,如果要在文件中保存字符串,为什么要使用XML?一个简单的文本文件是不够的?它不仅仅是字符串。这只是第一个元素。我有一个合适的网页,包含下拉列表、单选按钮和文本字段。它工作正常,但输出没有显示我在文本框中输入的内容。在一般信息中,它给了我这个
System.Web.UI.WebControls.TextBox
.Syrion是的,我复制了你输入的代码,因为我不知道你的需要,但替换为Text属性,很高兴你解决了你的问题我很高兴帮助你Syrion它正在工作,但输出没有显示我在文本框中输入的内容。在一般信息中,它给了我这个
System.Web.UI.WebControls.TextBox
.Syrion是的,我复制了你输入的代码,因为我不知道你的需要,但替换为Text属性,很高兴你解决了你的问题我很高兴帮助你Syrion