Quantcast
Viewing all articles
Browse latest Browse all 935

How to use XPathNavigator.ReplaceSelf to update more than one XMLnode

In Below program only first <title> is getting modified 

I want to update all the occurrences of title how to do this ?

public static void Main()
  {
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice 1</title>" +
                "<title>Pride And Prejudice 2</title>" +
                 "<title>Pride And Prejudice 3</title>" +
                "<title>Pride And Prejudice 4</title>" +
                "</book>");

    XPathNavigator navigator = doc.CreateNavigator();

    XPathNodeIterator nodes =
      navigator.Select("book/title");

    foreach (XPathNavigator item in nodes)
    {
      item.ReplaceSelf("<title>New Data</title>");
    }
  }
}


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>