7.9. Join and Query Multiple XML Documents

Problem

You need to perform queries based on the combination of two XML documents that have a common key.

Solution

Use either the Join or Group Join query clause available in System.Xml.Linq.

How It Works

LINQ allows you to perform SQL-like queries on various data sources, such as XML. These queries support the ability to join multiple data sources based on a common key using the Join or Group Join clause.

Recipe 7-6 mentions how you can perform in-depth queries on XML data using the LINQ to XML API, and recipe 6-11 covers the Join and Group Join LINQ clauses in detail.

The Code

The following code loads the contents of two XML files (employees.xml and tasks.xml) and uses the Group Join LINQ clause to ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.