I'm writing a program to parse some third-party XML files. The structure is something like...
<CharacterSheet>
...
<StatBlock>
...
<Stat>
...
<alias />
...
</Stat>
...
</StatBlock>
...
</CharacterSheet>
I'm using this in to get some practice with linq, and I'm fining I have to write some really ugly chained queries to get what I want, a list of stats and all their alias.
var CharSheet = from i in character.Elements()
where i.Name == "CharacterSheet"
select i;
var StatBlocks = from sheet in CharSheet
from statBlock in sheet.Elements()
where statBlock.Name == "StatBlock"
select statBlock;
var stats = from statBlock in StatBlocks
from stat in statBlock.Elements()
select stat;
var statAliases = from stat in stats
from alias in stat.Elements()
where alias.Name == "alias"
select new { stat, alias };
And I realize I could make that into one really long query using "into" (which is originally how I had it), but that just made it even more dense and difficult to work with.
It seems like there's got to be a simpler way to do what I'm trying to do.