Replacing the innertext of an Xml node/element

前端 未结 1 547
余生分开走
余生分开走 2020-12-11 15:47

First of all this is C#. I am creating a internet dashboard for a small group of colleages in the NHS. Below is an example xml file in which I need to change the innertext

相关标签:
1条回答
  • 2020-12-11 16:35

    Using XmlDocument and XPath you can do this

    XmlDocument doc = new XmlDocument();
    doc.Load(reader); //Assuming reader is your XmlReader
    doc.SelectSingleNode("buttons/workshop1").InnerText = "new text";
    

    You can use doc.Save to save the file also.

    Read more about XmlDocument on MSDN.

    EDIT

    To save the document do this

    doc.Save(@"C:\myXmFile.xml"); //This will save the changes to the file.
    

    Hope this helps you.

    0 讨论(0)
提交回复
热议问题