更新后如何保存xml资源文件?

时间:2013-05-11 05:06:34

标签: c# xmldocument

我正在使用C#来附加xml资源文件。

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(Properties.Resources.setup_info);
XmlNode node = xmlDoc.SelectSingleNode("data/Ename");
node.Attributes[1].Value = "true";

在此之后我需要保存资源文件。但

xmlDoc.Save(path);//needs the file path

如果我给“Properties.Resources.setup_info”抛出错误。

1 个答案:

答案 0 :(得分:0)

您可以使用ResourceWriter执行此任务

以下是MSDN的示例代码

using System;
using System.Resources;


public class WriteResources {
   public static void Main(string[] args) {

      // Creates a resource writer.
      IResourceWriter writer = new ResourceWriter("myResources.resources");

      // Adds resources to the resource writer.
      writer.AddResource("String 1", "First String");

      writer.AddResource("String 2", "Second String");

      writer.AddResource("String 3", "Third String");

      // Writes the resources to the file or stream, and closes it.
      writer.Close();
   }
}
下面的

会将xml写入资源文件ProjXML.resources

  using (ResourceWriter rw = new ResourceWriter(@".\ProjXML.resources"))
  {
     rw.AddResource("MyXML",  xmlDoc.OuterXml);
  }