Help with a LINQ XML Join

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to get my arms around using LINQ to join two xml documents, and Im in need of some help. This is featuregroups.xml:
<?xml version="1.0" encoding="utf-8" ?><br/>
<featuregroupcollection><br/>
<featuregroup><br/>
<featuregroupvalue>Series A</featuregroupvalue><br/>
<featurecollection><br/>
<featureid>professional</featureid><br/>
<featureid>doubles</featureid><br/>
<featureid>wimbledon</featureid><br/>
</featurecollection><br/>
</featuregroup><br/>
<featuregroup><br/>
<featuregroupvalue>Series B</featuregroupvalue><br/>
<featurecollection><br/>
<featureid>gaming</featureid><br/>
<featureid>automotive</featureid><br/>
<featureid>cloudcomputing</featureid><br/>
<featureid>consumer</featureid><br/>
</featurecollection><br/>
</featuregroup><br/>
<featuregroup><br/>
<featuregroupvalue>Series C</featuregroupvalue><br/>
<featurecollection><br/>
<featureid>empowerment</featureid><br/>
<featureid>johnmcenroe</featureid><br/>
<featureid>Individual</featureid><br/>
<featureid>automotive</featureid><br/>
<featureid>research</featureid><br/>
</featurecollection><br/>
</featuregroup> <br/>
</featuregroupcollection>
... and this is a shortened version of featuremaster.xml:
<?xml version="1.0" encoding="utf-8" ?><br/>
<featuremasterdata><br/>
<feature><br/>
<featureid>Individual</featureid><br/>
<featuretype>Individual</featuretype><br/>
<featurevalue>Individual</featurevalue><br/>
</feature><br/>
<feature><br/>
<featureid>education</featureid><br/>
<featuretype>Audience</featuretype><br/>
<featurevalue>Education</featurevalue><br/>
</feature><br/>
<feature><br/>
<featureid>professional</featureid><br/>
<featuretype>Audience</featuretype><br/>
<featurevalue>Professional</featurevalue><br/>
</feature><br/>
<feature><br/>
<featureid>government</featureid><br/>
<featuretype>Audience</featuretype><br/>
<featurevalue>Government</featurevalue><br/>
</feature><br/>
<feature><br/>
<featureid>automotive</featureid><br/>
<featuretype>Audience</featuretype><br/>
<featurevalue>Automotive</featurevalue><br/>
</feature><br/>
<feature><br/>
<featureid>retail</featureid><br/>
<featuretype>Audience</featuretype><br/>
<featurevalue>Retail</featurevalue><br/>
</feature><br/>
</featuremasterdata>
I would like to join these on <featureid> and return the <featuregroupvalue> values corresponding to each <featureid>.<br/>
I have found a number of excellent posts on the topic of joins and XML but Im not succeeding at applying the principals in them to my particular situation. For example many of the examples I found start with an array as the data source and I havent
quite figured out how to adapt those to my scenario with XML data sources. I think I need to simultaneously learn about LINQ, IEnumerable, IQueryable, lambda expressions and Im a little overwhelmed.
Can you show me an example of a LINQ query that does the kind of join described above?
Thanks,
Larry

View the full article
 
Back
Top