Hi @Markus Freitag ,
Your query looks fine to me, except the duplicate Element()
method. You can try to use the XContainer.Descendants Method, which returns a collection of the descendant elements for this document or element, in document order.
By using the Descendants method, the query looks like this:
var lastDraw = xdoc.Root?.Descendants("DRAWOBJECT").Where(c => c.Attribute("type").Value.ToLower() == "text").FirstOrDefault();
string speed = lastDraw.Element("MARKSPEED").Attribute("v").Value;
string POWER = lastDraw.Element("POWER").Attribute("v").Value;
string frequence = lastDraw.Element("CODETYPE").Attribute("v").Value;
var lastDraw2 = xdoc.Root?.Descendants("DRAWOBJECT").Where(c => c.Attribute("type").Value.ToLower() == "2d" || c.Attribute("type").Value.ToLower() == "text").ToList();
if (lastDraw2 != null)
{
var result = from s in lastDraw2
select new
{
Speed2 = s.Element("MARKSPEED").Attribute("v").Value,
Power2 = s.Element("POWER").Attribute("v").Value
};
}
The result is like this:
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.
Best regards,
Dillion