<----------------------------------------->
easy xml creation
<----------------------------------------->
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace XML_test_new
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
XmlNode xmlRoot, xmlNode;
xmlRoot = xmldoc.CreateElement("Root");
xmldoc.AppendChild(xmlRoot);
xmlNode = xmldoc.CreateElement("Child");
xmlRoot.AppendChild(xmlNode);
xmlNode.InnerText = "This is the first Child";
// you can also take a textbox instead of the text like this;
// xmlNode.InnerText = TextBox1.Text;
xmlNode = xmldoc.CreateElement("Child2");
xmlRoot.AppendChild(xmlNode);
xmlNode.InnerText = "This is the second Child";
xmlNode = xmldoc.CreateElement("Child3");
xmlRoot.AppendChild(xmlNode);
xmlNode.InnerText = "This is the third Child";
// you can make as many childs as you want
string filename = @"c:\" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + ".xml";
// i wanted the date as the filename, so i can see when it was created
// of course you can change it to:
// string filename = @"c:\NewXML" + ".xml" or @"c:\whatever" + ".xml"
xmldoc.Save(filename);
}
}
}
Abonner på:
Legg inn kommentarer (Atom)
Ingen kommentarer:
Legg inn en kommentar