Skip to content

Instantly share code, notes, and snippets.

@dheaney
Created April 18, 2016 13:40
Show Gist options
  • Save dheaney/8ba1684767ecc4738481ab01b05f8bd6 to your computer and use it in GitHub Desktop.
Save dheaney/8ba1684767ecc4738481ab01b05f8bd6 to your computer and use it in GitHub Desktop.
using System;
using System.Data.SqlClient;
using System.Xml;
using Gtk;
public partial class MainWindow: Gtk.Window
{
private XmlDocument doc;
private XmlNodeList nodes;
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
doc = new XmlDocument ();
try {
doc.Load ("Data.xml");
} catch(System.Exception) {
Console.WriteLine ("Error");
}
nodes = doc.GetElementsByTagName ("item");
// Set-up GUI
this.labelNameEntries.Text = "";
this.labelURLEntries.Text = "";
this.labelName.Text = "Name";
this.labelUrl.Text = "URL";
this.submit.Label = "Submit";
updateDisplay ();
}
private void updateDisplay()
{
this.labelNameEntries.Text = "";
this.labelURLEntries.Text = "";
Console.WriteLine (nodes.Count.ToString());
for (int i = 0; i < nodes.Count; i++)
{
XmlNode node = (XmlNode) nodes.Item (i);
this.labelNameEntries.Text += node.FirstChild.InnerText + '\n';
this.labelURLEntries.Text += node.LastChild.InnerText + '\n';
}
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected void clicked (object sender, EventArgs e)
{
string name = this.entryTitle.Text;
string number = this.entryURL.Text;
XmlElement item = doc.CreateElement ("item");
XmlElement title = doc.CreateElement("title");
title.InnerText = name;
XmlElement url = doc.CreateElement ("url");
url.InnerText = number;
item.AppendChild (title);
item.AppendChild (url);
doc.GetElementsByTagName ("channel") [0].AppendChild (item);
Console.WriteLine (doc.OuterXml);
doc.Save("Data.xml");
updateDisplay ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment