Hi, Markus Freitag
Distinct Method returns distinct elements from a sequence.
An XML file must have one and only one root node, and all other nodes must be its child nodes. In your example there are three root nodes.
You can print the root node before the loop.
Trace.WriteLine(result.Root!.Name);
foreach (var name in result.Root!.DescendantNodes().OfType<XElement>().Select(x => x.Name))
{
switch (name.LocalName)
{
case "LANEA":
Trace.WriteLine("aa Name: " + name.LocalName);
break;
case "LANEB":
Trace.WriteLine("bb Name: " + name.LocalName);
break;
case "LANEC":
Trace.WriteLine("cc Name: " + name.LocalName);
break;
default:
Trace.WriteLine(name);
break;
}
}
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.