如何替换或更新XML文件中的节点文本?

时间:2016-01-12 07:20:00

标签: c# xml

以下是我的XML数据

<?xml version="1.0" encoding="utf-8"?>
<students>
<student>
<name>James</name>
<age>34</age>
</student>
<student>
<name>Shawn</name>
<age>30</age>
</student>
<student>
<name>Scott</name>
<age>35</age>
</student>
</students>

下面是我的c#代码

XmlDocument myxml = new XmlDocument();
string path;
private void update_Click(object sender, EventArgs e)
    {
//to fetch aplication path 
        path =System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
        myxml.Load(@"" + path + "/samplexml.xml");

//here i need to write a code 
// when i click update button i will pass new name(through textbox) to the existing node in XML file, example there is a node name called Shawn but i want to change  Shawn.k when i click update button this is the requirement 


    }

如果知道解决方法,请帮助我。

0 个答案:

没有答案