Increment a xml with c# -


ok have run bind work. have xml document trying change. value has change every time file has downloaded. when file finishes downloading version.xml has id want change "0" "1". can set launcher way want here code have.

private void getnextnodeid()     {         xmldocument doc = new xmldocument();         doc.load(@"version.xml");         var x = doc.getelementsbytagname("product");         int max = 0;            max++         xmlelement newelement = doc.createelement("product");         newelement.setattribute("id", max.tostring());          doc.save(@"version.xml");      } 

also here xml document

<table> <product> <product>0</product> <product_name>vitare</product_name> <product_version>1.0.0.1</product_version> </product> </table> 

now reason code never messes xml file please me figure out how increment value!!!!!!!!!

thank , devin magaro

currently you're creating new element using document, never adding document. you're trying set attribute had text within element itself.

assuming want update element, i'd use linq xml instead of xmldocument:

var doc = xdocument.load("version.xml"); // single() ensures there's 1 such element var element = doc.descendants("product").single();  int currentvalue = (int) element; element.setvalue(currentvalue + 1); doc.save("version.xml"); 

if want update all product elements, should loop on doc.descendants("product") foreach loop.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -