我有一个XML(这正是它的样子):
<PolicyChangeSet schemaVersion="2.1" username="" description="">
<Attachment name="" contentType="">
<Description/>
<Location></Location>
</Attachment>
</PolicyChangeSet>
Run Code Online (Sandbox Code Playgroud)
这是在用户的机器上.
我需要为每个节点添加值:用户名,描述,附件名称,内容类型和位置.
这是我到目前为止:
string newValue = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlNode node = xmlDoc.SelectSingleNode("/PolicyChangeSet");
node.Attributes["username"].Value = AppVars.Username;
node.Attributes["description"].Value = "Adding new .tiff image.";
node.Attributes["name"].Value = "POLICY";
node.Attributes["contentType"].Value = "content Typeeee";
//node.Attributes["location"].InnerText = "zzz";
xmlDoc.Save(filePath);
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachment/Description").InnerText = "My Description";
xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachment/Location").InnerText = "My Location";
Run Code Online (Sandbox Code Playgroud)
明白了这个——
xmlDoc.Load(filePath);
XmlNode node = xmlDoc.SelectSingleNode("/PolicyChangeSet");
node.Attributes["username"].Value = AppVars.Username;
node.Attributes["description"].Value = "Adding new .tiff image.";
node = xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachment");
node.Attributes["name"].Value = "POLICY";
node.Attributes["contentType"].Value = "content Typeeee";
xmlDoc.Save(filePath);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64499 次 |
| 最近记录: |