前提・実現したいこと
kmlファイルを解析し<name></name>で囲まれている範囲の文字列を抽出したい
該当のソースコード
<kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <name>登録店舗</name> <description><![CDATA[地図の説明<br>]]></description> <Style id="icon-1541-FF5252-labelson"> <IconStyle> <color>ff5252ff</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1541-FFEA00-labelson"> <IconStyle> <color>ff00eaff</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1541-FFEA00-labelson-nodesc"> <IconStyle> <color>ff00eaff</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> <BalloonStyle> <text><![CDATA[<h3>$[name]</h3>]]></text> </BalloonStyle> </Style> <Style id="icon-1639-0F9D58-labelson"> <IconStyle> <color>ff589d0f</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1639-0F9D58-labelson-nodesc"> <IconStyle> <color>ff589d0f</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> <BalloonStyle> <text><![CDATA[<h3>$[name]</h3>]]></text> </BalloonStyle> </Style> <Style id="icon-1644-0288D1-labelson"> <IconStyle> <color>ffd18802</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1644-FF5252-labelson"> <IconStyle> <color>ff5252ff</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1700-F57C00-labelson"> <IconStyle> <color>ff007cf5</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1739-0288D1-labelson"> <IconStyle> <color>ffd18802</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> </Style> <Style id="icon-1739-0288D1-labelson-nodesc"> <IconStyle> <color>ffd18802</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> </IconStyle> <BalloonStyle> <text><![CDATA[<h3>$[name]</h3>]]></text> </BalloonStyle> </Style> <Style id="icon-1899-0288D1-normal"> <IconStyle> <color>ffd18802</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> <hotSpot x="32" xunits="pixels" y="64" yunits="insetPixels"/> </IconStyle> <LabelStyle> <scale>0</scale> </LabelStyle> </Style> <Style id="icon-1899-0288D1-highlight"> <IconStyle> <color>ffd18802</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> <hotSpot x="32" xunits="pixels" y="64" yunits="insetPixels"/> </IconStyle> <LabelStyle> <scale>1</scale> </LabelStyle> </Style> <StyleMap id="icon-1899-0288D1"> <Pair> <key>normal</key> <styleUrl>#icon-1899-0288D1-normal</styleUrl> </Pair> <Pair> <key>highlight</key> <styleUrl>#icon-1899-0288D1-highlight</styleUrl> </Pair> </StyleMap> <Style id="icon-1899-0288D1-labelson-nodesc"> <IconStyle> <color>ffd18802</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> <hotSpot x="32" xunits="pixels" y="64" yunits="insetPixels"/> </IconStyle> <BalloonStyle> <text><![CDATA[<h3>$[name]</h3>]]></text> </BalloonStyle> </Style> <Style id="icon-1899-FF5252-labelson"> <IconStyle> <color>ff5252ff</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> <hotSpot x="32" xunits="pixels" y="64" yunits="insetPixels"/> </IconStyle> </Style> <Style id="icon-1899-FF5252-labelson-nodesc"> <IconStyle> <color>ff5252ff</color> <scale>1</scale> <Icon> <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href> </Icon> <hotSpot x="32" xunits="pixels" y="64" yunits="insetPixels"/> </IconStyle> <BalloonStyle> <text><![CDATA[<h3>$[name]</h3>]]></text> </BalloonStyle> </Style> <Folder> <name>UberEats店舗位置.xlsx</name> <Placemark> <name>1101sai cafe</name> <address>福岡県福岡市中央区大手門3-1-13</address> <description>福岡県福岡市中央区大手門3-1-13</description> <styleUrl>#icon-1739-0288D1-labelson</styleUrl> </Placemark> <Placemark> <name>ABBEY</name> <address>福岡県福岡市中央区薬院2-4-5 103 大稲マンション1-B</address> <description>福岡県福岡市中央区薬院2-4-5 103 大稲マンション1-B</description> <styleUrl>#icon-1739-0288D1-labelson</styleUrl> </Placemark> <Placemark> <name>B.B.M バーガービッグマウンテン</name> <address>福岡県福岡市中央区薬院1-16-5</address> <description>福岡県福岡市中央区薬院1-16-5</description> <styleUrl>#icon-1739-0288D1-labelson</styleUrl> </Placemark>
試したこと
初歩的な質問になりますが、nokogiriでhtml,xml形式以外のファイルを解析することは可能なのでしょうか。
kmlファイル解析、x path指定方法等、ご教授頂ければ幸いです。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
提示された断片はxmlとして不完全のようですが
これで全部なのでしょうか?
また、Nokogiriで読み込もうとした際のコードも提示していただけますか?
回答1件
あなたの回答
tips
プレビュー