ここで頭がおかしいだけではないことを願っていますが、.NET で独自の KML クラスを作成し、.net シリアル化を使用して、エクスポート時に実際に XML を生成しようとしています。目印に関しては、この 1 つの部分にこだわっています。Google の API によると、KML には、特にドキュメント コンテナのルートに目印が必要です。したがって、次のようなものです。
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>text.xml</name>
<open>1</open>
<Placemark id="PM1">
<name>PM1 Full Name</name>
<description>Full Description...</description>
<Point id="g0">
<altitudeMode>clampToGround</altitudeMode>
<extrude>1</extrude>
<coordinates>-74.001,40.001,0</coordinates>
</Point>
</Placemark>
<Placemark id="PM2">
<name>PM3 Full Name</name>
<description>Full Description...</description>
<Point id="g1">
<altitudeMode>clampToGround</altitudeMode>
<extrude>1</extrude>
<coordinates>-74.000,40.000,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Placemarks は Document のルートにあり、"Placemarks" などと呼ばれる別の要素ではないことに注意してください。それで、シリアル化を使用して.NETでそれを行う方法。私はこのようなものを作成しました:
public class Document
{
[XmlElement("name")]
public string Name { set; get; }
[XmlElement("open")]
public int Open { set; get; }
//This will Serialize to a container <Placemarks>...</Placemarks>
public List<Placemark> Placemarks { set; get; }
}
public class Placemark
{
public Placemark() { }
public Placemark(string name, string desc)
{
Name = name;
Description = desc;
}
[XmlElement("name")]
public string Name { set; get; }
[XmlElement("description")]
public string Description { set; get; }
}
しかし、それは余分な要素 <Placemarks>...</Placemarks> を生成します。
ありがとう
コメントに返信するには、次のサンプル コードを確認してください。
したがって、これがコードの出力です。
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<name>Test.xml</name>
<open>0</open>
<Placemarks>
<Placemark>
<name>Mark0</name>
<description>What I am...</description>
</Placemark>
<Placemark>
<name>Mark1</name>
<description>What I am...</description>
</Placemark>
<Placemark>
<name>Mark2</name>
<description>What I am...</description>
</Placemark>
</Placemarks>
</Document>