我试图让一个程序不断地将数据写入文件中的 XML 节点,但我不确定如何实现它。XML 文件是一个 Google 地球 kml 文件,需要坐标才能绘制路径:
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style>
<LineStyle>
<color>7f00ffff</color>
<width>4</width>
</LineStyle>
</Style>
<Placemark>
<LineString>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>0,0,0</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
我只需要修改坐标节点并添加后续行。这将使用计时器来完成,以每秒写入一组新坐标。这可能有数百行:
<coordinates>
-112.2550785337791,36.07954952145647,2357
-112.2549277039738,36.08117083492122,2357
-112.2552505069063,36.08260761307279,2357
-112.2564540158376,36.08395660588506,2357
-112.2580238976449,36.08511401044813,2357
-112.2595218489022,36.08584355239394,2357
(...etc)
</coordinates>
我不太了解如何仅访问坐标节点并在值之后写入值。我已经尝试过这样的事情,但它不工作:
XmlDocument dataFile = new XmlDocument();
dataFile.Load("gpsData.kml");
XmlNode node = dataFile.SelectSingleNode("kml/Document/Placemark/LineString/coordinates");
node.InnerText (?) <- how do I append new text instead of replacing the whole thing?