问题描述
< employee>
< employee>
< id> 1
< userid> arvind
< password> 123456
< isactive> false
< employee>
< ; id> 2
< userid> tarun
< password> 123
< isactive> false
<employee>
<employee>
<id>1
<userid>arvind
<password>123456
<isactive>false
<employee>
<id>2
<userid>tarun
<password>123
<isactive>false
推荐答案
string xmlstr = @"<employees>
<employee>
<id>1</id>
<userid>arvind</userid>
<Password>123456</Password>
<isactive>false</isactive>
</employee>
<employee>
<id>2</id>
<userid>tarun</userid>
<Password>123</Password>
<isactive>false</isactive>
</employee>
</employees>";
XmlDocument document = new XmlDocument();
document.LoadXml(xmlstr);
XmlNode employee = document.SelectSingleNode("//employee[id='2']");
employee["Password"].InnerText = "newpass";
请注意以下几点:
- 我想你必须从文件加载(使用正确的方法)
- 我选择了员工ID = 2
- 我使用 employee s 作为根元素.Yous根元素也是员工。
- 这是内存更新,您可能需要保存结果
Please note followings:
- I suppose you will have to load from file (use proper method)
- I have selected the Employee with ID=2
- I have used employees as root element. Yous root element was also employee.
- This was an in-memory update, you will probably have to save the result
这篇关于我想在asp.net的XML文件中更改密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!