Получить значения из XML - C#
Формулировка задачи:
Добрый день, помогите решить проблему
Как мне считать отсюда Temperature?
я пробивал так:
Но получаю ошибку, наверно через это:
но не знаю как исправить, помогите пожалуйста
<Regions>
<Region RegionName="Some Region" />
<City CityName="Some City">
<Date>11.09.2016</Date>
<PartOfDay Part="Ночь">
<Temperature>30</Temperature>
<FeelsLike>29</FeelsLike>
</PartOfDay>
<PartOfDay Part="Утро">
<Temperature>30</Temperature>
<FeelsLike>29</FeelsLike>
</PartOfDay>
<PartOfDay Part="День">
<Temperature>30</Temperature>
<FeelsLike>29</FeelsLike>
</PartOfDay>
<PartOfDay Part="Вечер">
<Temperature>30</Temperature>
<FeelsLike>29</FeelsLike>
</PartOfDay>
<WindSpeed>5</WindSpeed>
<AtmosphericPressure>550</AtmosphericPressure>
</City>
</Region>
var s = from item in region where item.Attribute("RegionName").Value == "Some Region" where item.Attribute("CityName").Value=="Some City" where item.Attribute("Part").Value=="День" select item.Element("Temperature").Value;var region = docRead.Descendants("Region");Решение задачи: «Получить значения из XML»
textual
Листинг программы
string xml = Resources.weather;
XElement root = XElement.Parse(xml);
string regionName = "Some Region";
string cityName = "Some City";
string partOfDay = "Ночь";
double? s = (double?)root
.Elements("Region").Where(x => (string)x.Attribute("RegionName") == regionName)
.Elements("City").Where(x => (string)x.Attribute("CityName") == cityName)
.Elements("PartOfDay").Where(x => (string)x.Attribute("Part") == partOfDay)
.Elements("Temperature").FirstOrDefault();