Prev | Current Page 79 | Next

Satheesh, N Kumar

"LINQ Quickly"

WriteLine(nod.ToString());
}
The equivalent of the above code is as follows:
foreach (XElement nod in
LoadClassicIcecreamsFile.Elements())
{
Console.WriteLine(nod.Value);
}
LINQ to XML
[ 48 ]
We can also get a particular element based on the name. We can use the overloaded
method Elements (XName), which takes XName as parameter. For example, the
following code is used for getting the Name element of the icecreams.xml file..
foreach (XElement nod in LoadClassicIcecreamsFile.
Elements("Icecream"))
{
Console.WriteLine(nod.Element("Name").Value);
}
If the XElement node has more than one child element, we can use the Elements
method to traverse through the child elements. If we have only one child element,
we can directly point to that using the Element method. In the above code we are
looping through the Icecreams element as it has many children. Inside the loop, we
have directly used the Element method to get the Name element from the tree as there
is no child element for the Name. Following are some more examples of traversing
through the XML and getting information about the nodes:
foreach (XElement node in
LoadClassicIcecreamsFile.


Pages:
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
życzenia ślubne typy bukmacherskie Tango Olsztyn dieta light wierszyki