Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;//****************************
using System.Xml.Serialization;//**************
namespace XMLİslemleri
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
/*
XML İŞLEMLERİ
Veri tasımak ıcın kullanılır.
XML yazma ve okuma ıslemlerını yapan mekanızmalara XML Parser denir. .NET ortamında XML Parserlar System.XML isim alanı altında bulunmalıdr. .NET ortamında XML verileri uzerinde çalışmayı saglayan sınıflar temelde iki farklı yaklasım uzerınden tasarlanmıstır.
1-String tabanlı yaklasım (Stream Style Parser)
2-DOM(Document Object Model-Dokuman Nesne Modeli) Tabanlı yaklasım(DOM Style Parser)
Stream tabanlı parserlar DOM a gore daha az belek alanı ısgal edıp Daha hızlı calısırlar.Ilerı dogru satır satır okuma yaparlar.DOM parserlar dokuman agacında kı tum varlıkları aynı anda goosterebılme yetenegne sahıptır.
*/
//Stream Tabanlı Parser
XmlTextReader xrd = new XmlTextReader(@"C:Calismakisiler.xml");
label1.Text += "Durum:" + xrd.ReadState+"n";
while (xrd.Read())
{
//label1.Text += "Düğüm:" + xrd.Name + "Değer:" + xrd.Value + "n";
if (xrd.NodeType==XmlNodeType.Text)
label1.Text += xrd.Value + " " + xrd.Name + "n";
}
xrd.Close();
label1.Text += "Durum:" + xrd.ReadState + "n";
//Close() okuma ıslemı ıcın kullanılan kaynakların ıade edıldıgı anlamına gelır.Ayrıca readstate durumu closed olarak bıldırılır.
XmlTextWriter xwrt = new XmlTextWriter(@"C:CalismaUrunler.xml", null);
xwrt.WriteStartElement("Urunler");
xwrt.WriteStartElement("Urun");
xwrt.WriteElementString("UrunKodu", "1");
xwrt.WriteElementString("Urunadi", "Muz");
xwrt.WriteElementString("Fiyat", "2,50");
xwrt.WriteElementString("Miktar", "100");
xwrt.WriteElementString("Birim", "KG");
xwrt.WriteEndElement();
xwrt.WriteStartElement("Urun");
xwrt.WriteElementString("UrunKodu", "2");
xwrt.WriteElementString("Urunadi", "Kivi");
xwrt.WriteElementString("Fiyat", "3,50");
xwrt.WriteElementString("Miktar", "80");
xwrt.WriteElementString("Birim", "KG");
xwrt.WriteEndElement();
xwrt.WriteEndElement();
xwrt.Close();
/*
DOM STYLE PARSER
Stream Parsera gore daha yavas calısırlar ve bellekte daha fazla yer tutarlar ama daha karmasık ıslemlerı gerceklestırebılmemıze olanak saglarlar.
*/
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:CalismaUrunler.xml");
label1.Text = "";
XmlNodeList xNodes = xDoc.GetElementsByTagName("Urun");
//foreach (XmlNode item in xDoc.GetElementsByTagName("Urun"))// bu satırda bır dızıye yollarız dızı uzerınde otomtık doner ve yazar alttakı ıle aynı ısı yapar.
//foreach (XmlNode item in xNodes)
//{
// label1.Text += item.InnerText + "n";
//}
//Arama İşlemi
string xmlara = "//Urun[Urunadi='Muz']";
XmlNode xnod = xDoc.SelectSingleNode(xmlara);
label1.Text += xnod.InnerText;
//xDoc'e yeni Node
XmlElement xeleman = xDoc.CreateElement("urun");
xDoc.DocumentElement.AppendChild(xeleman);
//Urunkodu
XmlElement xCocuk = xDoc.CreateElement("urunkodu");
XmlText xtext = xDoc.CreateTextNode("3");
xCocuk.AppendChild(xtext);
xeleman.AppendChild(xCocuk);
//UrunAdi
xCocuk = xDoc.CreateElement("urunadi");
xtext = xDoc.CreateTextNode("ekmek");
xCocuk.AppendChild(xtext);
xeleman.AppendChild(xCocuk);
//Fiyat
xCocuk = xDoc.CreateElement("fiyat");
xtext = xDoc.CreateTextNode("1");
xCocuk.AppendChild(xtext);
xeleman.AppendChild(xCocuk);
//Miktar
xCocuk = xDoc.CreateElement("Miktar");
xtext = xDoc.CreateTextNode("500");
xCocuk.AppendChild(xtext);
xeleman.AppendChild(xCocuk);
//Birim
xCocuk = xDoc.CreateElement("Birim");
xtext = xDoc.CreateTextNode("adet");
xCocuk.AppendChild(xtext);
xeleman.AppendChild(xCocuk);
xDoc.Save(@"C:Calismaurunler.xml");
Eleman eleman = new Eleman() { ID = 5, Ad = "Kamil", Soyad = "Kazan" };
//Serialize
}
}
class Eleman
{
public int ID { get; set; }
public string Ad { get; set; }
public string Soyad { get; set; }
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team