conver c# text value in xml.

Bageshkumarbagi
Posted by Bageshkumarbagi under C# category on | Points: 40 | Views : 880
*************************c# code*********************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace TextToXML
{

public partial class Form1 : Form
{
private XmlDocument doc;
private XmlElement root;
public string PATH = @"C:\Person.xml";
public Form1()
{
InitializeComponent();
}
private void btnWritetoXML_Click(object sender, EventArgs e)
{
XmlWriter xmlWriter = XmlWriter.Create(PATH);

xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Person");

xmlWriter.WriteStartElement("Name");
xmlWriter.WriteString(txtName.Text);
xmlWriter.WriteEndElement();

xmlWriter.WriteStartElement("Age");
xmlWriter.WriteString(txtAge.Text);
xmlWriter.WriteEndElement();

xmlWriter.WriteStartElement("Address");
xmlWriter.WriteString(txtAddress.Text);
xmlWriter.WriteEndElement();

xmlWriter.WriteEndDocument();

xmlWriter.Close();

}
}
}

output
<?xml version="1.0" encoding="utf-8"?>
<Person>
<Name>Bagesh Kumar Singh</Name>
<Age>25</Age>
<Address>Pune</Address>
</Person>


}

Comments or Responses

Login to post response