Reputation: 147
I have been trying to do this in C# to write a class for xml files in my folder to replace NULL value for MyXmlElement12 with Value from MyXmlElement as below +datetimestamp:
<MyXmlType>
<MyXmlElement>Value</MyXmlElement>
<MyXmlElement12></MyXmlElement12>
</MyXmlType>
Could someone please help? I have been able to get the value from first element and add a time stamp as below. But how do I update the second xml tag with this value replacestring
I have below?
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("/", "");
}
Upvotes: 0
Views: 1217
Reputation: 1838
XDocument doc = XDocument.Load(Path);
doc.Element("MyXmlType")
.Element("MyXmlElement12")
.Value += DateTime.Now.ToString();
doc.Save(Path);
Upvotes: 1