I have the XML (not exactly this simple but just enough for my question).
If I code like the following
var xdoc = XDocument.Parse(@"
<Root>
<Item>
<Node1>Value 1</Node1>
<Node2>Value 2</Node2>
<Node3>Value 3</Node3>
<Node4>Value 4</Node4>
<Node5>Value 5</Node5>
<Node6>Value 6</Node6>
</Item>
</Root>");
var results = xdoc.Root
.Elements("Item")
.Descendants()
.Select(e => new { ElementName = e.Name, ElementValue = e.Value });
This will give me the result list of all descendants (node name and node value) of the "Item" element. What I want to ask is how do I get different set of data depending on the condition. For example, if Node1 or Node2 has a value (not empty), then I want the result list of Node1 and Node2 (node name and value) only, otherwise the result list should show the other nodes which is Node3, Node4, Node5 and Node6 (node name and value). Please help. Thank you.