I am trying to parse this piece of XML
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<DagUren>
<Chauffeur>Vincent</Chauffeur>
<AanmeldTijd>4 dec. 2012 09:05:42</AanmeldTijd>
<Gewerkt>04:42</Gewerkt>
</DagUren>
I created a DagUren class that contains strings with Chauffer, AanmeldTijd, Gewerkt, etc.
DagUren eenDagUren
= (from du in doc.Element("DagUren")
select new DagUren
{
Chauffeur = du.Element("Chauffeur").Value,
Gewerkt = du.Element("Gewerkt").Value,
Pauze = du.Element("Pauze").Value,
AanmeldTijd = du.Element("AanmeldTijd").Value,
}
);
The compiler respons with: Could not find an implementation of the query pattern for source type ‘System.Xml.Linq.XElement’. ‘Select’ not found.
Please advice, i’ve spend quite some time on it rewriting, every guide is using a different approach…
Your problem is, that
Element()does not return a collection ofXElementit just returns a single object. Linq just queries collections of items, not single objects. So your solution would be: