Click here to Skip to main content
14,456,063 members
Rate this:
Please Sign up or sign in to vote.
See more:
hai friends i need to update an xml file with node attributes my xml structure is
<BankName BankName="jinesh" TemplateModel="sam">
  <column Name="ChqDate" X="10" Y="10" />
  <column Name="CPayAgainst" X="10" Y="10" />
  <column Name="ChqAmtDgt" X="10" Y="10" />
  <column Name="ChqAmtWrds" X="10" Y="10" />

i need to update the elements in the XandYPosition node so i created a function for this but i am not able to complete this .please help me to achieve this

public static void updatenode(string bankname, string templatemodel,string field,string x,string y)
        XDocument doc = XDocument.Load("newtest.xml");
       var  updatenode = doc
                    .Where(item => item.Attribute("BankName").Value == bankname && item.Attribute("TemplateModel").Value == templatemodel)
                    .Select(XandYPosition => XandYPosition.Descendants("XandYPosition").Descendants());

function call will be like this
BasicClass.updatenode(comboBox1.Text, comboBox2.Text, "ChqDate", "1000", "2000");
Rate this:
Please Sign up or sign in to vote.

Solution 2

//yor localhost is related to your application
var xelement = XElement.Load("http://localhost:1694/newtest.xml");

var query = (from m in xelement.Descendants("BankName")
             where m.Attribute("BankName").Value == "jinesh" && m.Attribute("TemplateModel").Value == "sam"
             from b in m.Element("XandYPosition").Elements("column")
             where b.Attribute("Name").Value == "ChqDate"
             select b).FirstOrDefault();

if (query != null)


//Combine by foreach from xelement+queryresult --> new xml (newtest) and newtest.Save("..\\..\\newtest.xml");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100