Part 1 LINQ to XML

preview_player
Показать описание
If you are a foodie like me, I am sure you will enjoy the recipes on my friend's YouTube channel. If you find them useful, please subscribe and share to support her. She's really good at what she does.

Creating an XML document using LINQ to XML.

Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Slides

LINQ to SQL Tutorial - All Text Articles & Slides

LINQ to XML Tutorial Playlist

Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses

What is Functional Construction?
As far as LINQ to XML is concerned there is a technical term called Functional Construction. First let us understand what this term means with an example. Functional construction is the ability to create an XML tree in a single statement.

Let us now discuss, creating an an XML tree in a single statement.

All the classes to create an XML document are present in System.Xml.Linq namespace. To create
XML Document use XDocument class
XML Declaration use XDeclaration class
XML Comment use XComment class
XML Element use XElement class
XML Attribute use XAttribute class
Code to create the XML Document
using System.Xml.Linq;

namespace Demo
{
class Program
{
public static void Main()
{
XDocument xmlDocument = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),

new XComment("Creating an XML Tree using LINQ to XML"),

new XElement("Students",

new XElement("Student", new XAttribute("Id", 101),
new XElement("Name", "Mark"),
new XElement("Gender", "Male"),
new XElement("TotalMarks", 800)),

new XElement("Student", new XAttribute("Id", 102),
new XElement("Name", "Rosy"),
new XElement("Gender", "Female"),
new XElement("TotalMarks", 900)),

new XElement("Student", new XAttribute("Id", 103),
new XElement("Name", "Pam"),
new XElement("Gender", "Female"),
new XElement("TotalMarks", 850)),

new XElement("Student", new XAttribute("Id", 104),
new XElement("Name", "John"),
new XElement("Gender", "Male"),
new XElement("TotalMarks", 950))));

}
}
}

Рекомендации по теме
Комментарии
Автор

Veknat!
I am a great fan of you tutorials. I have never seen anyone who use simple words to explain complicated subjects!
Thank you, my friend!

aaraaivon
Автор

Once again, I call upon whoever is responsible for awarding MVP at Redmond to get in here to see this Star-Author ! Many thanks Venkat ! You deserve multiple MVP awards for this great work. God bless ..

folorunso
Автор

You're the best! I love your tutorials.

sunilanthony
Автор

bro so fucking helpful. theres legit no good documentation with this at all! appreciate it so much my god.

Sumdottycoy
Автор

Thank you so much!
Can you please show us how we can create the xml document from MS SQL server table, Excel and/or CSV file instead of hardcoding everything?
I am actually looking for a way to automate the XML schema file creation.
Thank you so much!!!!
You are the best!

mocanada
Автор

Brilliant! Do you also have a video on how to use an existing XML-file as a template for this? Maybe some way of making classes from an existing XML. I am trying to generate a series of xml-files for a library of folders and files and read some info from these file into the XML.

christerjohanzzon
Автор

Really thanks, your video is amazing.

NoOne-zlqb
Автор

How to save the data? seems dont have write access to C drive.

TheWhiteboardAI
Автор

Literally wasting my money doing a computer science degree

yosifthamer
visit shbcf.ru