[Help] Fix a code about value of element/node in xml file.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all, a have a 1 file database xml, I add it to my Project Winform C#, now I want when I debug it show a value of element/node bookID had Encryption by method Encryption MD5 or SHA in textbox, Are you understand ? Now here is xml file, picture demo and
code, please fix for me, thank very much:
<?xml version="1.0" encoding="utf-8"?><br/>
<data><br/>
<book><br/>
<bookID>1111</bookID><br/>
<bookName>English</bookName><br/>
<bookPrice>2$</bookPrice><br/>
</book><br/>
<book><br/>
<bookID>222</bookID><br/>
<bookName>USA</bookName><br/>
<bookPrice>3$</bookPrice><br/>
</book><br/>
<book><br/>
<bookID>3333</bookID><br/>
<bookName>Singapore</bookName><br/>
<bookPrice>4$</bookPrice><br/>
</book><br/>
</data>
Here is a picture when I debug, it havent still encryption bookID:
http://i1055.photobucket.com/albums/s505/vn_photo/sss.jpg
Here is picture required I want when debug finish:
http://i1055.photobucket.com/albums/s505/vn_photo/sse.jpg
Here is my code:
private void Form1_Load(object sender, EventArgs e)<br/>
{<br/>
//LoadXml("book.xml");<br/>
XmlDocument xml = new XmlDocument();<br/>
xml.Load("book.xml");<br/>
XmlNodeList xnList = xml.SelectNodes("/data[bookID]");<br/>
foreach (XmlNode xn in xnList)<br/>
{<br/>
XmlNode encryption = xn.SelectSingleNode("bookID");<br/>
if (encryption != null)<br/>
{<br/>
string pass = encryption["bookID"].InnerText;<br/>
XmlNodeList CNodes = xn.SelectNodes("book");<br/>
foreach (XmlNode node in CNodes)<br/>
{<br/>
XmlNode encryption1 = node.SelectSingleNode("bookID");<br/>
if (encryption1 != null)<br/>
{<br/>
string md5 = EncrypSHA1(encryption1["bookID"].InnerText);<br/>
}<br/>
}<br/>
}<br/>
}<br/>
xml.Save("book.xml");<br/>
LoadXml("book.xml");<br/>
}<br/>
<br/>
private void LoadXml(string FILE_NAME)<br/>
{<br/>
if (!File.Exists(FILE_NAME))<br/>
{<br/>
MessageBox.Show("No find database!", "Notify!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);<br/>
return;<br/>
}<br/>
StreamReader sr = File.OpenText(FILE_NAME);<br/>
String input;<br/>
input = sr.ReadToEnd();<br/>
sr.Close();<br/>
textBox1.Text = input;<br/>
}<br/>
<br/>
private static string EncrypSHA1(string sMaHoa)<br/>
{<br/>
UTF32Encoding utf32 = new UTF32Encoding();<br/>
byte[] bytes = utf32.GetBytes(sMaHoa);<br/>
//Encoding.UTF32.GetBytes(<br/>
SHA1 md = new SHA1CryptoServiceProvider();<br/>
MD5 md5 = new MD5CryptoServiceProvider();<br/>
byte[] kq = md.ComputeHash(bytes);<br/>
byte[] kq2 = md5.ComputeHash(kq);<br/>
return Convert.ToBase64String(kq2);<br/>
}



<br/>

View the full article
 
Back
Top