c# - Modify values in xml -


i have xml file in following format :

 <?xml version="1.0" encoding="utf-8"?>     <server xmlns="urn:jboss:domain:1.2">   <extensions>     <extension module="org.jboss.as.clustering.infinispan" />     <extension module="org.jboss.as.cmp" />     <extension module="org.jboss.as.ejb3" />   </extensions>     <appsettings>       <property name="external_fileserver" value="/site/bugbase.adobe.com/files/" />       <property name="ftp_user" value="password" />       <property name="ftp_server" value="sjshare.corp.adobe.com"/>       <property name="ftp_password" value="password" />       <property name="ftp_read_user" value="password" />       <property name="ftp_read_pass" value="password" />       <property name="workflow_notification_template" value="util/workflow_notification_template.html"/>     </appsettings> </server> 

i wanted change password values "ftp_user" , "ftp_read_user".

code tried far :

xmldocument doc = new xmldocument();             string path = @"c:\users\karansha\desktop\config file 1.xml";             doc.load(path);             doc.selectnodes("/appsettings/property").item(1).attributes["value"].value = "newpassword";             doc.selectnodes("/appsettings/property").item(2).attributes["value"].value = "new_password"; 

instead of doing

doc.selectnodes("/appsettings/property").item(1).attributes["value"].value = "password1"; 

use foreach loop

xmldocument doc = new xmldocument(); string path = @"c:\users\karansha\desktop\config file 1.xml"; doc.load(path);  foreach (xmlnode selectnode in doc.selectnodes("/appsettings/property")) {     if(selectnode.attributes["name"].value.equals("ftp_user") ||        selectnode.attributes["name"].value.equals("ftp_read_user"))     {         selectnode.attributes["value"].value = "new_password";     } }  doc.save(path);  

and if need 2 different passwords

    if(selectnode.attributes["name"].value.equals("ftp_user"))     {         selectnode.attributes["value"].value = "new_password";     }      if(selectnode.attributes["name"].value.equals("ftp_read_user"))     {         selectnode.attributes["value"].value = "newpassword";     } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -