Im using Visual studio 2019 and I would like to load, edit and save xml file.
xml file:
<?xml version="1.0" encoding="utf-8"?>
<Firstdelivery25 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.acm.nl/Operations/2018/09">
<Firstdelivery>
<MessageId xmlns="http://www.acm.nl/DataModel/2018/09">
<Source>ABC</Source>
</MessageId>
</Firstdelivery>
</Firstdelivery25>
Code in Visual studio:
using System.Linq;
using System.Xml.Linq;
using System.Xml;
using TechTalk.SpecFlow;
XDocument xdoc = XDocument.Load(@"C:\\XML files\\25.xml");
var element = xdoc.Elements("Source").FirstOrDefault();
if (element != null)
{
element.Value = "DEF";
}
xdoc.Save(@"C:\\VB_25.xml");
When I execute this, the test is passed successfully. However, when I open the new created VB_25.xml file, the old value is still there.
Any help/suggestions/tips would be appreciated.