My xml layout has changed since going into production. So, i need to read the file and, if the Facility element is missing, add it in.
Old xml:
<SrvConfig>
<HostAddress>dev123.home.com</HostAddress>
<WhsNumber>03</WhsNumber>
<SrvPath>/appl/03/wt4090/</SrvPath>
</SrvConfig>
Desired xml:
<SrvConfig>
<HostAddress>dev123.home.com</HostAddress>
<WhsNumber>03</WhsNumber>
<SrvPath>/appl/03/wt4090/</SrvPath>
<Facility>MFG</Facility>
</SrvConfig>
So my code to read it:
Can someone helpme out with the insert and write bit? Thanks!
Old xml:
<SrvConfig>
<HostAddress>dev123.home.com</HostAddress>
<WhsNumber>03</WhsNumber>
<SrvPath>/appl/03/wt4090/</SrvPath>
</SrvConfig>
Desired xml:
<SrvConfig>
<HostAddress>dev123.home.com</HostAddress>
<WhsNumber>03</WhsNumber>
<SrvPath>/appl/03/wt4090/</SrvPath>
<Facility>MFG</Facility>
</SrvConfig>
So my code to read it:
Code:
XmlNode node;
XmlDocument doc = new XmlDocument();
//open xml file
doc.Load(srvCfgPathAndName);
//find element of interest
node = doc.SelectSingleNode("/SrvConfig/HostAddress");
_currServerIP = node.InnerText;
node = doc.SelectSingleNode("/SrvConfig/WhsNumber");
_currWhs = node.InnerText;
node = doc.SelectSingleNode("/SrvConfig/SrvPath");
_currPath = node.InnerText;
//since Facility wasnt part of original design we
//may need to add it for existing devices
node = doc.SelectSingleNode("/SrvConfig/Facility");
if (node == null)
{
//somehow insert it and write it back out
}
Can someone helpme out with the insert and write bit? Thanks!