The XML file content is as follows: site. config
Code
<? XML version = " 1.0 " Encoding = " UTF-8 " ?>
< Sites >
< Site siteid = " 1 " Securitylevel = "" Publickey = "" Publicandprivatekey = "" Fromurlkey = "" Cryptkeyfield = "" Ivkeyfield = "" >
</ Site >
< Site siteid = " 2 " Securitylevel = "" Publickey = "" Publicandprivatekey = "" Fromurlkey = "" Cryptkeyfield = "" Ivkeyfield = "" >
</ Site >
</ Sites >
Read XML
Code
String Export path = Path. Combine (appdomain. currentdomain. basedirectory, " Sites. config " );
Xmldocument Doc = New Xmldocument ();
Doc. Load (upload path );
Xmlelement Root = Doc. documentelement; // : Get the root system. xml. xmlelement of the document.
Xmlnode Node = Root. selectsinglenode ( String . Format ( " Site [@ siteid = '{0}'] " , Siteid )); // Select the first xmlnode that matches the XPath expression.
Xmlattribute ATT = Node. attributes [ " Publickey " ];
If (ATT ! = Null )
{
_ Publickey = Att. value;
}
Write XML
Code
String Export path = System. Io. Path. Combine (appdomain. currentdomain. basedirectory, " Sites. config " );
Xmldocument Doc = New Xmldocument ();
Doc. Load (upload path );
Xmlelement Root = Doc. documentelement;
Xmlnode Node = Doc. createelement ( " Site " ); // Create an element with the specified name
Xmlattribute ATT = Doc. createattribute ( " Siteid " ); // Create attributes
Att. Value = _ Siteid;
Node. Attributes. append (ATT );
Root. appendchild (node );
Doc. Save (export path );