vb.net - How to programatically add nodes at certain locations in xml config file -
we have our software installed on 50 client pcs.
the software picks values xml config file. each client has own personal node values (true/false) in config file.
now releasing new version of software few more nodes in xml config file.
how add new nodes clients existing config files while retaining node values (true/false).
note we have provide script client cannot manually!
sample xml:
<?xml version="1.0" encoding="utf-8"?> <applicationsettings xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <dbengine>true</dbengine> <enableauditlogging>true</enableauditlogging> <schema> <fileno>05</fileno> </schema> <nodetobeadded1> <xml/> <xml/> </nodetobeadded1> <nodetobeadded2> <defaultpath="c:\"/> </nodetobeadded2> <exportto> <exportto> <id>0</id> <path>c:\</path> </exportto> </exportto> </applicationsettings>
here's basic code can start with.
imports system.xml public class form1 private sub test() dim xdoc xmldocument dim root xmlnode dim n xmlnode xdoc = new xmldocument() xdoc.load("f:\tmp\a.xml") root = xdoc.selectsinglenode("/applicationsettings") if xdoc.selectsinglenode("/applicationsettings/nodetobeadded1") _ nothing n = root.insertafter( xdoc.createnode(xmlnodetype.element, "nodetobeadded1", ""), xdoc.selectsinglenode("/applicationsettings/schema")) n.appendchild( xdoc.createnode(xmlnodetype.element, "xmlsubsomething", "")) end if xdoc.save("f:\tmp\b.xml") end sub end class
Comments
Post a Comment