ace1234 Bronze Marketer
Posts : 59 Reputation : 5 Join date : 2012-06-24
| Subject: Writing a basic XML file with C# (ELEMENT) Fri Jun 29, 2012 9:19 am | |
| I had a bit of down time today and decided to work on other portions of Element today. The code below shows how to write a XML file via C#. Those of you working on Element can modify this code to accomodate the server logs, login, etc. I will probably use something similiar in the packet transmissions for the communication code. - Spoiler:
using System; using System.Text; using System.IO;
namespace login { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { // // TODO: Add code to start application here // string userid, pwd, conn;
Console.Write("Login Name: "); userid = Console.ReadLine(); Console.Write("Password: "); pwd = Console.ReadLine();
// one line per xml entry //conn = "<userid>" + userid + "</userid> <pwd>" + pwd + "</pwd>"; http://Console.WriteLine("{0}",conn);
WriteFile("<connection>");
string timeStamp = "<timestamp>" + DateTime.Now + "</timestamp>"; Console.WriteLine("{0}",timeStamp); WriteFile(timeStamp);
conn = "<userid>" + userid + "</userid>"; Console.WriteLine("{0}",conn); WriteFile(conn);
conn = "<pwd>" + MyXOR(pwd) + "</pwd>"; Console.WriteLine("{0}",conn); WriteFile(conn);
WriteFile("</connection>"); }
public static void WriteFile(string data) { // create a writer and open the file TextWriter tw = new StreamWriter(@"conn.xml",true); // write line of text to the file tw.WriteLine(data);
// close the stream tw.Close(); }
static string MyXOR (string data) { string key = "test"; string retValue = ""; int i = 0; int x = 0;
int[] cipher = new int[data.Length];
x = 0; for (i = 0; i < data.Length; i++) { http://Console.Write((char)((data[i] ^ key[x]))); retValue = retValue + (char)((data[i] ^ key[x])); cipher[i] = (data[i] ^ key[x]); x++; if (x >= key.Length) x = 0; }
return retValue; }
} }
| |
|