前提
KMLファイルを読み込み、白地図を作成したいです。
実現したいこと
KMLファイルの読み込み
発生している問題
XMLファイルと同様の操作をしても、うまく読み込めない。
(XMLファイルでは動作確認済み)
該当のソースコード
C#
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using System.ComponentModel; 5using System.Data; 6using System.Drawing; 7using System.Linq; 8using System.Text; 9using System.Threading.Tasks; 10using System.Windows.Forms; 11using System.Xml; 12using System.Xml.Linq; 13using System.IO; 14using System.Runtime.InteropServices; 15 16 17namespace mapquest_homework 18{ 19 20 public partial class Form1 : Form 21 { 22 [DllImport("kernel32.dll")] 23 private static extern bool AllocConsole(); 24 25 [DllImport("kernel32.dll")] 26 private static extern bool FreeConsole(); 27 28 /// <summary> 29 /// Windows FormアプリケーションでConsoleを利用する最低限のサンプル 30 /// </summary> 31 32 private string[][] DataArray; 33 private ArrayList debug = new ArrayList(); 34 35 public Form1() 36 { 37 InitializeComponent(); 38 AllocConsole(); 39 } 40 41 private void DataLoadButton_Click(object sender, EventArgs e) 42 { 43 var xmlDoc = new XmlDocument(); 44 xmlDoc.Load(@"C:/Users/niino/Desktop/kmlファイル/kmlファイル/ITA_adm0.kml"); 45 var Placemark = xmlDoc.SelectNodes("kml/Document"); 46 47 48 49 foreach (XmlNode pl in Placemark) 50 { 51 debug.Add("aaa"); 52 53 //座標データの原本を格納 54 var data = pl.SelectSingleNode("name").InnerText; 55 debug.Add(data); 56 } 57 58 } 59 60 private void ShowConsoleButton_Click(object sender, EventArgs e) 61 { 62 63 Console.WriteLine("debugの要素数は:" + debug.Count); 64 65 for(int i = 0; i < debug.Count; i++) 66 { 67 Console.WriteLine(debug[i]); 68 } 69 } 70 } 71} 72
KMLfile
1<?xml version="1.0" encoding="UTF-8"?> 2<kml xmlns="http://earth.google.com/kml/2.2"> 3<Document> 4<name>Italy</name> 5<description><![CDATA[<a href='http://www.gadm.org'>GADM</a> boundaries.]]></description> 6 7<Style id="1"> 8<LineStyle> 9<width>1.5</width> 10<color>ff000000</color> 11</LineStyle> 12<PolyStyle> 13<color>aa0000df</color> 14<fill>1</fill> 15</PolyStyle> 16</Style> 17 18<Placemark> 19<name>Italy</name> 20 21//以下略
試したこと
XMLファイルではできていたので、KMLとXMLの違う点が問題だと考え、KMLファイルの二行目の xmins の部分を削り、<kmll></kml>のみにしたらうまく読み込めました。ただKMLファイル自体を加工したくないので、何とかC#のコードを改変して実現したいです。
補足情報(FW/ツールのバージョンなど)
VisualStudio2019
C# .NET Framework 4.7.2
windows form アプリケーション

回答1件
あなたの回答
tips
プレビュー