私はc#内でlinqクエリを使い始めたばかりで、必要なすべてのデータを取得するのに苦労しています。
基本的に、私はgoogleearthkmlファイルをxmlファイルとして使用しています。
構造はこんな感じ。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Placemark>
<name>XXX</name>
<description>XXX</description>
<styleUrl>XXX</styleUrl>
<Point>
<coordinates>XXX</coordinates>
</Point>
</Placemark>
</Document>
</kml>
コードをそのまま使用すると、最初のレベルの要素(name、description、styleurl)を取得できますが、Point内の座標要素を取得するために構文を正しく取得できません。誰かが私を正しい方向に向けることができますか?私が苦労している行は、Coord = p.Element(ns + "Point")。Element(ns + "coordinates")。Valueです。これはどうあるべきですか?
XNamespace ns = "http://earth.google.com/kml/2.2";
var placemarks = xdoc.Descendants(ns + "Placemark")
.Select(p => new
{
Name = p.Element(ns + "name").Value,
Desc = p.Element(ns + "description").Value,
Coord = p.Element(ns + "Point")
.Element(ns + "coordinates").Value
}).ToList();