我想獲得一個程序來連續將數據寫入文件中的XML節點,但我不知道如何實現它。 XML文件是需要以座標繪製路徑的谷歌地球KML文件:XML不斷更新值
<?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?
中還引用了這個文本文件你*有*使用XmlDocument的?是否使用LINQ to XML代替? –
'node.InnerText = node.InnerText + myOtherText'? –