Scott Klein
"Professional LINQ"
Annotations
();
foreach (TestAnnotation val2 in TestAnnoList)
{
if (loopCount == 1)
{
listbox1.Items.Add(val2.Tag1);
}
else
{
listbox1.Items.Add(val2.Tag2);
}
loopCount += 1;
}
This code produces the following results:
1
2
3
500
Scooter
It??™s just that easy to add annotations to elements and attributes of an XML tree, and to retrieve the
annotation values.
160
Chapter 8: Advanced LINQ to XML Programming Topics
LINQ to XML Axis
LINQ to XML provides the capability to query an XML to find elements and attributes and return their
respective values. You have seen in previous chapters how to ??????walk??™??™ an XML tree to find a specific value
of an element or attribute, but what if you want to return a value for more than one node? Suppose that
you want to return all the FirstName elements, for example. How would you do that?
LINQ to XML provides this capability through axis methods, which are methods on the XElement class,
each of which returns an IEnumerable collection. These methods can be used to return the structured, or
complex, content of a node such as child and ancestor elements.
Pages:
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279