Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

УНОС И ПРИКАЗ XML

WebForm – Adresar.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Xml;
using System.Data;

namespace Working_with_XML
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string filename = Server.MapPath("Adresar.xml");

XmlDocument xdoc = new XmlDocument();


xdoc.Load(Server.MapPath("Adresar.xml"));

XmlElement Osoba = xdoc.CreateElement("Osoba");

XmlElement Ime = xdoc.CreateElement("Ime");


XmlText xmlIme = xdoc.CreateTextNode(TextBox1.Text);

XmlElement Prezime = xdoc.CreateElement("Prezime");


XmlText xmlPrezime = xdoc.CreateTextNode(TextBox2.Text);

XmlElement Adresa = xdoc.CreateElement("Adresa");


XmlText xmlAdresa = xdoc.CreateTextNode(TextBox3.Text);

Ime.AppendChild(xmlIme);
Prezime.AppendChild(xmlPrezime);
Adresa.AppendChild(xmlAdresa);

Osoba.AppendChild(Ime);
Osoba.AppendChild(Prezime);
Osoba.AppendChild(Adresa);

xdoc.DocumentElement.AppendChild(Osoba);

xdoc.Save(Server.MapPath("Adresar.xml"));

protected void Button2_Click(object sender, EventArgs e)


{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("Adresar.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}

XML – Adresar.xml
<?xml version="1.0" encoding="utf-8" ?>

<Adresar>

<Osoba>

<Ime>

</Ime>
<Prezime>

</Prezime>
<Adresa>

</Adresa>

</Osoba>

</Adresar>

You might also like