Question

<?xml version="1.0" ?> 
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
   <buttons>   
      <workshop1>hello</workshop1>  
       <workshop1>Google</workshop1>    
      <url1>www.google.co.uk</url1> 
    </buttons>
    </Reports>

Above is my xml file .how should i change inner text of Duplicate Node.for Exampla in Above xml i have to change Second node Google to yahoo using XPath in c#.Thanks

Was it helpful?

Solution

Declare proper prefix to namespace URI mapping, then you can use XPath query using that prefix plus specifying element index to select the second <workshop1> element, for example :

XmlDocument doc = new XmlDocument();
doc.Load("C:\\test.xml");
XmlNamespaceManager oManager = new XmlNamespaceManager(doc.NameTable);
oManager.AddNamespace("ns", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
var google = doc.SelectSingleNode("/ns:Report/ns:buttons/ns:workshop1[2]", oManager).InnerText;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top