Xml eXtensible M


Download 1.13 Mb.
bet2/19
Sana26.06.2023
Hajmi1.13 Mb.
#1656026
1   2   3   4   5   6   7   8   9   ...   19
Bog'liq
Majmua

Natijamiz:

XmlWriter sinfi yordamida:
XmlWriter sinfining metodlari:

XmlWriter sinfining metodlaridan va yuqoridagi model va ketma-ketlikdan foydalanib yangi Talabalar.xml nomli hujjat hosil qilamiz.
XmlWriter sinfidan yangi obyekt hosil qilish uchun dastlab uning sozlamalarini hosil qilish kerak bo'ladi:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter obyektini Talabalar.xml fayli nomi va yuqoridagi settings bilan hosil qilamiz:
XmlWriter writer = XmlWriter.Create("Talabalar.xml", settings);
Talaba modelining xususiyatlarini kiritib, hujjatimizni hosil qilamiz:
writer.WriteStartDocument();
writer.WriteStartElement("Talabalar");
writer.WriteStartElement("Talaba");
writer.WriteStartElement("Id");
writer.WriteValue("1");
writer.WriteEndElement();
writer.WriteStartElement("Ism");
writer.WriteValue("Baxtiyor");
writer.WriteEndElement();
writer.WriteStartElement("Familiya");
writer.WriteValue("Murodov");
writer.WriteEndElement();
writer.WriteStartElement("TelNomer");
writer.WriteValue("+998901234567");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
3. XML hujjat hosil qilish uchun C# dasturlash tilida System.Xml.Linq nomlar fazosidagi XElement sinfidan ham foydalansak bo'ladi:
Va nihoyat men yoqtirgan usulga ham yetib keldik 😄!
XElement sinfi yordamida XML hujjat hosil qilish birmuncha oson va tushunarli. Har bir element va uning ichidagi elementlar shajaraga o'xshab joylashadi.
XElement talabalar =
new XElement("Talabalar",
new XElement("Talaba",
new XElement("Id", "1"),
new XElement("Ism", "Baxtiyor"),
new XElement("Familiya", "Murodov"),
new XElement("Tel_nomer", "+998901234567")));
talabalar.Save("Talabalar.xml");

Download 1.13 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   19




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling