C# 获取不规则的XML值
我从GPS互联网服务中得到了XML。它看起来像: 我需要从中得到X和Y的值,但我不知道怎么做 我尝试使用XDocument属性,但其检索值失败C# 获取不规则的XML值,c#,xml-parsing,linq-to-xml,C#,Xml Parsing,Linq To Xml,我从GPS互联网服务中得到了XML。它看起来像: 我需要从中得到X和Y的值,但我不知道怎么做 我尝试使用XDocument属性,但其检索值失败 有什么建议吗?类似于.Elements(“Property”)。其中(el=>el.Attribute(“Name”)。Value==“X”) 这将为您提供具有X属性的元素,之后您只需选择该元素的任何属性的值 类似于.Elements(“Property”).Where(el=>el.Attribute(“Name”).Value==“X”)
有什么建议吗?类似于
.Elements(“Property”)。其中(el=>el.Attribute(“Name”)。Value==“X”)
这将为您提供具有X属性的元素,之后您只需选择该元素的任何属性的值 类似于
.Elements(“Property”).Where(el=>el.Attribute(“Name”).Value==“X”)
var el = XElement.Parse(xml);
var x = el.Elements("Property").Where(e => e.Attribute("Name").Value == "X").Single().Attribute("Value").Value;
var y = el.Elements("Property").Where(e => e.Attribute("Name").Value == "Y").Single().Attribute("Value").Value;
这将为您提供具有X属性的元素,之后您只需选择该元素的任何属性的值
var el = XElement.Parse(xml);
var x = el.Elements("Property").Where(e => e.Attribute("Name").Value == "X").Single().Attribute("Value").Value;
var y = el.Elements("Property").Where(e => e.Attribute("Name").Value == "Y").Single().Attribute("Value").Value;
或
或
他是我的解决方案
gpsResponseXML.Descendants("Property").Where(el => el.Attribute("Name").Value == "X").Attributes("Value").FirstOrDefault().Value)
他是我的解决方案
gpsResponseXML.Descendants("Property").Where(el => el.Attribute("Name").Value == "X").Attributes("Value").FirstOrDefault().Value)
谢谢你给了我一个解决方案的想法见上文我的解决方案谢谢你给了我一个解决方案的想法见上文我的解决方案