Amaliy matematika fakulteti


XML hujjat hosil qilish uchun C# dasturlash tilida System.Xml.Linq


Download 0.53 Mb.
bet3/7
Sana28.10.2023
Hajmi0.53 Mb.
#1731569
1   2   3   4   5   6   7
Bog'liq
Hosil web dasturlash mustaqil ish1

XML hujjat hosil qilish uchun C# dasturlash tilida System.Xml.Linq nomlar fazosidagi XElement sinfidan ham foydalansak bo'ladi.
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");
XML hujjatni JSON fayllar kabi Serialize qilish orqali ham yaratishimiz mumkin. Buning uchun bizga System.Xml.Serialization nomlar fazosidagi sinflar kerak bo'ladi.
Dastlab Talaba modelimizga [Serializable] attributini qo'shishimiz kerak bo'ladi:
[Serializable]
public class Talaba
{
public int Id { get; set; }
public string Ism { get; set; }
public string Familiya { get; set; }
public string TelNomer { get; set; }
}
Yangi Talaba obyektini xususiyatlari bilan yaratamiz va Talabalar listiga qo'shamiz:
Talaba talaba = new Talaba
{
Id = 1,
Ism = "Baxtiyor",
Familiya = "Murodov",
TelNomer = "+998901234567"
};
List talabalar = new List();
talabalar.Add(talaba);
Obyektimizni serialize qilamiz va TextWriter yordamida Talabalar.xml nomi bilan saqlaymiz:
XmlSerializer serializer = new XmlSerializer(typeof(List));
TextWriter twriter = new StreamWriter("Talabalar.xml");
serializer.Serialize(twriter, talabalar);
twriter.Close();



body{
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
overflow-y: hidden;
background-color: black;
}
.container{
position: absolute;
width: 550px;
height: 550px;
transform-style: preserve-3d;
transform: perspective(600px) rotate(0deg);

}
.container span{
position: absolute;
display: block;
box-sizing: border-box;
border: 2px solid white;
margin: 10px;
box-shadow: 0 0 10px white;
animation: span 40s ease-in-out infinite;
}

Download 0.53 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




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