This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// Load the Inventory.xml document into memory



Download 21,46 Mb.
Pdf ko'rish
bet1655/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   1651   1652   1653   1654   1655   1656   1657   1658   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Load the Inventory.xml document into memory.

XElement doc = XElement.Load("Inventory.xml");



// We will author each of these next...

PrintAllPetNames(doc);

Console.WriteLine();

GetAllFords(doc);

Console.ReadLine();

}

The PrintAllPetNames() method illustrates the use of the XElement.Descendants() method,



which allows you to directly specify a given subelement you wish to navigate to in order to apply a

LINQ query expression. Here we are selecting each PetName value and printing out the contents to

the console:

static void PrintAllPetNames(XElement doc)

{

var petNames = from pn in doc.Descendants("PetName")



select pn.Value;

foreach (var name in petNames)

Console.WriteLine("Name: {0}", name);

}

The GetAllFords() method is very similar in nature. Given the incoming XElement, we define a



where operator and select the all XElements where the Make element is equal to the value "Ford":

static void GetAllFords(XElement doc)

{

var fords = from c in doc.Descendants("Make")



where c.Value == "Ford"

select c;

foreach (var f in fords)

Console.WriteLine("Name: {0}", f);

}

Figure 24-12 shows the output of this program.



C H A P T E R   2 4  

P R O G R A M M I N G   W I T H   T H E   L I N Q   A P I S



863

8849CH24.qxd  10/19/07  10:11 AM  Page 863




Figure 24-12.

LINQ to XML in action


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   1651   1652   1653   1654   1655   1656   1657   1658   ...   1830




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish