Greetings!
I have some XML like this:
<Root> <AlphaSection> . . . </AlphaSection> <BetaSection> <Choices> <SetA> <Choice id='choice1'> <Title>Choice 1 Title</Title> <Body>Choice 1 Body</Body> </Choice> <Choice id='choice2'> <Title>Choice 2 Title</Title> <Body>Choice 2 Body</Body> </Choice> </SetA> <SetB> <Choice id='choice3'> <Title>Choice 3 Title</Title> <Body>Choice 3 Body</Body> </Choice> <Choice id='choice4'> <Title>Choice 4 Title</Title> <Body>Choice 4 Body</Body> </Choice> </SetB> </Choices> </BetaSection> <GammaSection> . . . </GammaSection> </Root>
I’m currently doing the following to retrieve the ID of each choice:
var choiceList = myXDoc.Root .Element('BetaSection') .Descendants('Choice') .Select(element => new { ID = element.Attribute('id').Value, // Title = ? // Body = ? });
I’d also like to get the values in the Title and Body child nodes of each Choice. How would I go about it? Thanks.
1 Answer