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



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

// Build an XElement from string.

string myElement =

@"



Yellow

Yugo

";

XElement newElement = XElement.Parse(myElement);

Console.WriteLine(newElement);

Console.WriteLine();



// Load the SimpleInventory.xml file.

XDocument myDoc = XDocument.Load("SimpleInventory.xml");

Console.WriteLine(myDoc);

}



Source Code

The LinqToXmlBasics example can be found under the Chapter 24 subdirectory.



Navigating an In-Memory Document

So, that this point you have seen various ways in which LINQ to XML can be used to create, save,

parse, and load XML data. The next aspect of LINQ to XML we need to examine is how to navigate a

given document to locate specific elements/attributes. While the LINQ to XML object model pro-

vides a number of methods that can be used to programmatically navigate a document, not too

surprisingly LINQ query expressions can also be used for this very purpose.

Since you have already seen numerous examples of building query expressions, the next

example will be short and sweet. First, create a new Console Application named

NavigationWithLinqToXml and import the System.Xml.Linq namespace. Next, add a new XML

document into your current project named Inventory.xml, which supports a small set of entries

within the root  element. Here is one possibility:







Ford

Blue

Chuck







VW

Silver

Mary







Yugo

Pink

Gipper







Ford

Yellow

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



862

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



Max







BMW

Black

Zippy





Now, select this file within the Solution Explorer and use the Properties window to set the Copy

to Output Directory property to Copy Always (to ensure a copy of the file ends up in your Bin

folder). Finally, update your Main() method to load this file into memory using XElement.Load().

The local doc variable will be passed into various helper methods to modify the data in various

manners:


static void Main(string[] args)

{

Console.WriteLine("***** Fun with LINQ to XML *****\n");




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   1650   1651   1652   1653   1654   1655   1656   1657   ...   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