gpt4 book ai didi

c# - 解析XML和GPS数据以列出

转载 作者:行者123 更新时间:2023-12-03 17:18:14 25 4
gpt4 key购买 nike

<lap1>
<Track>
<Trackpoint>
<Time>2012-03-29T08:06:57Z</Time>
<Position>
<LatitudeDegrees>46.2950333</LatitudeDegrees>
<LongitudeDegrees>7.1046736</LongitudeDegrees>
</Position>
<AltitudeMeters>1782.4216309</AltitudeMeters>
<DistanceMeters>0.0000000</DistanceMeters>
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>112</Value>
</HeartRateBpm>
<SensorState>Absent</SensorState>
</Trackpoint>
<Trackpoint>
<Time>2012-03-29T08:06:58Z</Time>
<Position>
<LatitudeDegrees>46.2950271</LatitudeDegrees>
<LongitudeDegrees>7.1046776</LongitudeDegrees>
</Position>
<AltitudeMeters>1782.4216309</AltitudeMeters>
<DistanceMeters>0.1714377</DistanceMeters>
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>112</Value>
</HeartRateBpm>
<SensorState>Absent</SensorState>
</Trackpoint>
</Track>
</lap1>


我从我的gps设备中获得了这部分xml,我正在尝试将其解析为列表轨道

public class track
{
public float positionx;
public float positiony;
public float altitude;
public DateTime Time;
}


我并没有做太多的xml工作,我一直在阅读各种xml方法,包括XPath和LinqToXML,但是我却难以解析xml,尤其是'Position及其子值

我将非常感谢您对此提供的任何帮助

最佳答案

这应该可以解决问题:

XDocument doc = XDocument.Load("file.xml"); 

var tracks = (from elem in doc.Root.Descendants("Trackpoint")
select new track()
{
Time = DateTime.Parse(elem.Element("Time").Value, CultureInfo.InvariantCulture),
positionx = float.Parse(elem.Element("Positition").Element("LatitudeDegrees").Value, CultureInfo.InvariantCulture),
positiony = float.Parse(elem.Element("Positition").Element("LongitudeDegrees").Value, CultureInfo.InvariantCulture),
altitude = float.Parse(elem.Element("AltitudeMeters").Value, CultureInfo.InvariantCulture),
});


告诉我是否可行!

关于c# - 解析XML和GPS数据以列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9960033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com