Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows;
- using System.Xml;
- namespace YParaHoy
- {
- class GuardaXML
- {
- public void setCosas(String nombre, String detalle,
- String Fecha, Int16 grado)
- {
- this.ScribeXML(nombre, detalle, Fecha, grado);
- }
- private void MandaError(string str)
- {
- MessageBox.Show("" + str + "");
- }
- private void ScribeXML(String nombre, String detalle,
- String Fecha, Int16 grado)
- {
- try
- {
- String filename = "cosasAhacer.xml";
- XmlDocument xmlDoc = new XmlDocument();
- try
- {
- xmlDoc.Load(filename);
- }
- catch (System.IO.FileNotFoundException)
- {
- XmlTextWriter scribe = new XmlTextWriter(filename,
- System.Text.Encoding.UTF8);
- scribe.Formatting = Formatting.Indented;
- scribe.WriteProcessingInstruction("xml",
- "version='1.0' encoding='UTF-8'");
- scribe.WriteStartElement("Cosiacos");
- scribe.Close();
- xmlDoc.Load(filename);
- }
- XmlNode root = xmlDoc.DocumentElement;
- XmlElement Actividad = xmlDoc.CreateElement("Actividad");
- XmlElement Nombre = xmlDoc.CreateElement("Nombre");
- XmlElement Date = xmlDoc.CreateElement("Fecha");
- XmlElement Grado = xmlDoc.CreateElement("Grado");
- XmlElement Estado = xmlDoc.CreateElement("Estado");
- XmlElement Detalle = xmlDoc.CreateElement("Detalle");
- XmlText txtNom=xmlDoc.CreateTextNode(nombre),
- txtFecha=xmlDoc.CreateTextNode(Fecha),
- txtGrado=xmlDoc.CreateTextNode(grado.ToString()),
- txtEst=xmlDoc.CreateTextNode("Por Cumplir"),
- txtDate = xmlDoc.CreateTextNode(detalle);
- root.AppendChild(Actividad);
- Actividad.AppendChild(Nombre);
- Nombre.AppendChild(txtNom);
- Actividad.AppendChild(Date);
- Date.AppendChild(txtFecha);
- Actividad.AppendChild(Grado);
- Grado.AppendChild(txtGrado);
- Actividad.AppendChild(Estado);
- Estado.AppendChild(txtEst);
- Actividad.AppendChild(Detalle);
- Detalle.AppendChild(txtDate);
- xmlDoc.Save(filename);
- MessageBox.Show("Todo bien ;)", "Listoco");
- }
- catch (Exception ex)
- {
- MandaError(ex.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement