LINQ to
XML
When
we interact with XML using LINQ then it is known as LINQ to XML.
To work with XML in LINQ you have to add a namespace
using System.Xml.Linq.
I am taking the following xml
file for an example:-
<?xml version=”1.0”
encoding=”utf-8” ?>
<Techaltum>
<student
Code=”101”>
<name>isha
malhotra</name>
<id>
1 </id>
<course>
asp.net </course>
</student>
<student
Code=”102”>
<name>Avi
malhotra</name>
<id>
2 </id>
<course>
Web Designing </course>
</student>
<student
Code=”103”>
<name>Neha</name>
<id>
3 </id>
<course>
Java </course>
</student>
</Techaltum>
If I consider this xml file then
in this file first line is declaration. Techaltum is an element and in student
element code is attribute.
First I will discuss how to
declare all these in LINQ.
Syntax
of Declaration in LINQ:-
XDeclaration dec = new XDeclaration("1.0", "utf-8",
"yes");