c# - Replacing the innertext of an Xml node/element -


first of c#. creating internet dashboard small group of colleages in nhs. below example xml file in need change innertext of. need replace specific element example "workshop1." because have few workshops cannot afford use general writer because replace information on xml document 1 bit of code below.

<?xml version="1.0" ?>     <buttons>       <workshop1>hello</workshop1>        <url1>www.google.co.uk</url1>  

i using switch case select specific workshop can change name , add url of workshop , using code below replace whole document.

public void xmlw()     {         xmltextreader reader = new xmltextreader("c:\\myxmfile.xml");         xmldocument doc = new xmldocument();           switch (combobox1.text)          {             case "button1":                   doc.load(reader); //assuming reader xmlreader                  doc.selectsinglenode("buttons/workshop1").innertext = textbox1.text;                 reader.close();                 doc.save(@"c:\myxmfile.xml");                 break;           }       } 

so clarify want c# program search through xml document find element "workshop1" , replace innertext text textbox. , able save without replacing whole document 1 node. looking.

using xmldocument , xpath can this

xmldocument doc = new xmldocument(); doc.load(reader); //assuming reader xmlreader doc.selectsinglenode("buttons/workshop1").innertext = "new text"; 

you can use doc.save save file also.

read more xmldocument on msdn.

edit

to save document this

doc.save(@"c:\myxmfile.xml"); //this save changes file. 

hope helps you.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -