-6

可能重复:
LINQ TO XML,如何用新值替换值 c#

<BasicImport xmlns="http://www.uk.nds.com/SSR/XTI/Traffic/0010" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.uk.nds.com/SSR/XTI/Traffic/0010 0010.xsd" utcOffset="+05:30" frameRate="25">
  <SiEventSchedule deleteStart="2012/01/21 00:00:00" deleteEnd="2012/01/21 23:59:59">
    <siService>Saman</siService>
    <playoutSource>Saman</playoutSource>
    <activationSourceId>0</activationSourceId>
    <CaSchedule deleteStart="2012/01/21 00:00:00" deleteEnd="2012/01/21 23:59:59" />
    <SiEvent>
      <displayDateTime>2012/01/21 00:00:00</displayDateTime>
      <activationDateTime>2012/01/21 00:00:00</activationDateTime>
      <displayDuration>00:30:00</displayDuration>
      <siTrafficKey> 056049263</siTrafficKey>
      <detailKey>056049263 2012-07-12</detailKey>
     </SiEvent>
   </SiEventSchedule>
<BasicImport>

我只想替换<displayDateTime>节点的日期值。请注意,我不想更改此节点的时间值...请在 C# 代码中提供帮助

4

2 回答 2

0
var node = XElement.Load("LoadFrom");
                var TheNodeToChange = trayNode.Descendants("displayDateTime").First();
                var oldDateTime = DateTime.Parse(TheNodeToChange.Value);
                var newDateTime = oldDateTime;//.DoSomething();
                TheNodeToChange.Value = newDateTime.ToString();
于 2012-07-24T20:57:57.697 回答
0

DateTime 构造函数之一采用 Year、Month、Day、Hour、Minute、Second。因此,给定 OldDate,您可以使用

new DateTime( newYear, newMonth, newDay, OldHour, OldMinute, OldSecond)

于 2012-07-24T20:52:10.240 回答