Prev | Current Page 81 | Next

Satheesh, N Kumar

"LINQ Quickly"

ToString() + "\n");
}
Chapter 3
[ 49 ]
In the above example, we have many child elements under the Icecreams element.
If we have to get all the elements after a particular element, or before a particular
element, then we can use ElementsAfterSelf and ElementsBeforeSelf methods.
For example, following is the code to get all elements after the Name element and all
elements before the Protein element under the Icecreams element:
// Using ElementsAfterSelf()
string afterName = "";
string beforeProtein = "";
IEnumerable elementsAfterName =
IcecreamsDocument.Element("Icecreams")
.Element("Icecream").Element("Name").ElementsAfterSelf();
foreach (XElement ele in elementsAfterName)
{
afterName = afterName + ele.Value;
}
// Using ElementsBeforeSelf()
IEnumerable elementsBeforeProtein =
IcecreamsDocument.Element("Icecreams")
.Element("Icecream").Element("Protein")
.ElementsBeforeSelf();
foreach (XElement eleBefore in elementsBeforeProtein)
{
beforeProtein = beforeProtein + eleBefore.


Pages:
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
www.buciki.edu.pl Fundusze Emerytalne ufan.benton.pl basketball.sport24x7.net Battlefield 3 wygraj peb