This query returns a sequence of XElements containing the names of those whose first name begins with
the letter S. The data comes not from a self-generated XML document but an outside source, in this
case the array of first names. However, the data could just as easily come from a relational database or
even another XML document.
What XElement enables you to do is query non-XML sources and produce XML results via the utilization
of the XElements in the body of the select clause, as shown earlier. Gnarly.
The object of these simple examples is to illustrate the basic concepts of LINQ to XML and the great
power, flexibility, and ease with which XML can be manipulated. Note that the same standard query
operators were used to generate the XML document in this example as in the first one. Nothing had to
be changed in the query really, other than using the types to help integrate LINQ with XML to build the
resulting XML. Yet the query operators remained the same, as did the overall syntax of the query expression.
This way is much better than trying to figure out XQuery or XPath, working
with the DOM or even XSLT.
Pages:
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54