Guest User

Untitled

a guest
Jun 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Xml;
  9. using System.IO;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApplication27
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. zapis();
  20. cteni();
  21. }
  22. private void zapis()
  23. {
  24. XmlDocument doc = new XmlDocument();
  25. if (File.Exists("soubor.xml") == false)
  26. {
  27. FileStream fst = File.Create("soubor.xml");
  28. string sablona = "<?xml version=\"1.0\" encoding=\"windows-1250\"?><datumy></datumy>";
  29. fst.Close();
  30. File.WriteAllText("soubor.xml", sablona);
  31. }
  32.  
  33. doc.Load("soubor.xml");
  34.  
  35. XmlElement element = doc.CreateElement("spusteni");
  36. XmlAttribute atribut = doc.CreateAttribute("datum");
  37. atribut.Value = DateTime.Now.ToString();
  38.  
  39. element.SetAttributeNode(atribut);
  40.  
  41. doc.DocumentElement.InsertBefore(element, doc.DocumentElement.LastChild);
  42.  
  43. doc.Save("soubor.xml");
  44. }
  45. private void cteni()
  46. {
  47. XmlDocument doc = new XmlDocument();
  48. doc.Load("soubor.xml");
  49.  
  50. XmlNode root = doc.DocumentElement;
  51.  
  52. foreach (XmlNode node in root.ChildNodes)
  53. {
  54. label1.Text += Environment.NewLine + node.Attributes[0].Value;
  55. }
  56. }
  57. }
  58. }
Add Comment
Please, Sign In to add comment