0

我一直在尝试在 C# 中执行此操作,以便在我的文件夹中为 xml 文件编写一个类,以将 MyXmlElement12 的 NULL 值替换为来自 MyXmlElement 的值,如下所示 +datetimestamp:

<MyXmlType>
   <MyXmlElement>Value</MyXmlElement>
  <MyXmlElement12></MyXmlElement12>
</MyXmlType>

有人可以帮忙吗?我已经能够从第一个元素中获取值并添加一个时间戳,如下所示。但是如何使用replacestring下面的值更新第二个 xml 标记?

 public Form1()
 {
    InitializeComponent();
    XmlDocument doc = new XmlDocument();
    doc.Load("C:\\Users\\1\\1.xml");

    XmlNode node = doc.DocumentElement.SelectSingleNode("//MyXmlElement");

    string text = node.InnerText;
    string t = text + DateTime.Now.ToString();
    replacestring= t.Replace("/", "");
 }
4

1 回答 1

1
XDocument doc = XDocument.Load(Path);
doc.Element("MyXmlType")
   .Element("MyXmlElement12")
   .Value += DateTime.Now.ToString();
doc.Save(Path);
于 2013-06-04T21:56:08.850 回答