我有一个XML文件(就是它看起来的样子):
<PolicyChangeSet schemaVersion="2.1" username="" description="">
<Attachment name="" contentType="">
<Description/>
<Location></Location>
</Attachment>
</PolicyChangeSet>
这是在用户的计算机上。
我需要为每个节点添加值:用户名、描述、附件名称、内容类型和位置。
目前我的代码如下:
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);
有人可以帮忙吗?
node = xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachment/Location");
然后node.InnerText = "myLocation"
是在这里前进的方式。 - Jan