C#窗体给xml文档添加字节点时XmlElement怎么实例化?

图片说明

``` private void button1_Click(object sender, EventArgs e)
{
XmlDocument xdoc = new XmlDocument();
XmlDeclaration dec = xdoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
xdoc.AppendChild(dec);

        XmlElement ele = xdoc.CreateElement(textBox2.Text);
        xdoc.AppendChild(ele);
        xdoc.Save(textBox1.Text + ".xml");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        XmlDocument xdoc = new XmlDocument();
        xdoc.Load(textBox1.Text + ".xml");

        XmlElement ele = xdoc.CreateElement(textBox3.Text);
        xdoc.DocumentElement.FirstChild.AppendChild(ele);
        xdoc.Save(textBox1.Text + ".xml");

    }
查看全部
Iawfy_
Iawfy_
2020/11/03 10:55
  • c#
  • 点赞
  • 收藏
  • 回答
    私信

1个回复