Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. namespace EditorLocalizedStrings
  2.  
  3.  
  4. {
  5.     public partial class Form1 : Form
  6.     {
  7.         TableManager TM = new TableManager();
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.             TM.BindData(this.dataGridView1);
  12.            
  13.         }
  14.  
  15.         public class TableManager
  16.         {
  17.             private string _filePath;
  18.  
  19.             XmlElement documentElement;
  20.  
  21.             public bool isEnd()
  22.             {
  23.                 return true;
  24.             }
  25.             public string FilePath
  26.             {
  27.                 get { return _filePath; }
  28.                 set { _filePath = value; }
  29.             }
  30.  
  31.             private XmlElement BuildingXmlStructure()
  32.             {
  33.                 XmlDocument document = new XmlDocument();
  34.                
  35.                 try
  36.                 {
  37.                     document.Load(FilePath);
  38.                 }
  39.                 catch
  40.                 {
  41.  
  42.                 }
  43.                 documentElement = document.DocumentElement;
  44.                 return documentElement;
  45.             }
  46.              
  47.             public void BindData(DataGridView dgv)
  48.             {
  49.                 XmlNode node = BuildingXmlStructure();
  50.                 if(node != null)
  51.                 {
  52.                     foreach (XmlNode firstXMLNode in node.ChildNodes)
  53.                     {
  54.                         if (firstXMLNode.Name == "token")
  55.                         {
  56.                             XmlNode attr = firstXMLNode.Attributes.GetNamedItem("name");
  57.                             var i = dgv.Rows.Add();
  58.                             dgv.Rows[i].Cells[0].Value = attr.Value;
  59.                             dgv.Rows[i].Cells[1].Value = firstXMLNode.InnerText;
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.  
  66.  
  67.         private void Button2_Click(object sender, EventArgs e)
  68.         {
  69.             openFileDialog1.InitialDirectory = "c:\\";
  70.             openFileDialog1.Filter = "xml files (*.xml)|*.xml";
  71.  
  72.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  73.             {
  74.                 TM.FilePath = openFileDialog1.FileName;
  75.             }
  76.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement