LINQ to XML in action


We’re starting to see some real applications that demonstrate how easy it is to use LINQ to XML (I’m just gonna keep abbreviating it “XLinq”) to get real XML work done without too much sweat or tears.

One from a team member is Eric White’s Parsing WordML using XLinq

Recently, I had a problem where there wasn’t a code testing harness
that would do exactly what I wanted. I want to grab my code snippet
directly from my word document, compile it, run it, and validate the
output. 

In more technical terms, I want to parse some WordML to grab text
formatted with a given style. Further, I want to put a comment on the
first line of the formatted text, and be able to grab the comment. The
comment will contain the metadata that tells how to compile and run the
code.


My word docs are stored in WordML (which is XML). My experiment was
to see how easy it would be to pick apart the WordML using XLinq.


Another example is LINQ to Amazon

This example introduces Linq to Amazon, which allows
querying Amazon for books using Linq! It uses Linq’s extensibility to
allow for language-integrated queries against a book catalog. The Linq
query gets converted to REST URLs supported by Amazon’s web services.
These services return XML. The results are converted from XML to .NET
objects using Linq to XML.


Finally there’s Steve Eichert’s piece on the power of VB9’s XML Axis Properties that extend XLinq.  These greatly simplify the syntax needed to work with common XML types such as RSS, even when there is no schema:

   Return rss…<item>

This expressions uses the descendants axis support in VB 9 which can
be interpreted as: give me all “item” elements underneath the rss
element regardless of where they occur in the heirarchy.  VB9 also has
support for child axis’ which can be used to get all elements of a
given name directly under a given element.  For example to return all
the channel elements underneath the root rss element one could use the
following syntax.

   Return rss.<channel>

While Xml literals and axis properties aren’t something that is
likely to make or break a programmers language decision it does make
working with Xml in VB 9 a “pure joy” ®


Mike Champion


Comments (5)

  1. Yes, you read that right. LINQ to Amazon.

    Michael Champion has some more LINQ to XML in action coolness…

  2. margothcg_16@hotmail.com says:

    tengo un problema con mi sistema kiero ke lo desactive al sotfware corporation 4.20.98185.0 que fue intalado el 03/08/2006

  3. A few weeks ago I pulled together a post on LINQ to XML in action .&amp;nbsp; I came across a couple more…