I've come across different ways of getting the last element (there are several <hour>
elements and two other but only the last <hour>
element is the target needed) on the following link, e.g.:
XDocument xDoc = XDocument.Load("Source.xml");
XElement lastHour = doc.Root.Elements("hour").Last();
It doesn't work for me. When I put down 'dot' after Elements("hour")
, trying to call Last()
method, SharpDevelop doesn't see it. What's wrong with it?
The whole block of code is:
if (hour == hisDoc.Root.Elements("hour").Last) {
if ((hisDoc.Element("scanerHIS").Element("constants") != null) && (fcsDay.XPathSelectElement("constants") == null)) {
fcsDay.Add(new XElement("constants",
new XAttribute("P001", hisDoc.Root.XPathSelectElement("constants").Attribute("P001").Value),
new XAttribute("Q001", hisDoc.Root.XPathSelectElement("constants").Attribute("Q001").Value),
new XAttribute("N2", hisDoc.Root.XPathSelectElement("constants").Attribute("N2").Value),
new XAttribute("CO2", hisDoc.Root.XPathSelectElement("constants").Attribute("CO2").Value)));
}
}
fcsDoc.Save(FCSfileName);