этот пример использую
пример с git hub
мои изменения:
package main
import (
"fmt"
"encoding/xml"
"io/ioutil"
"os"
)
type Mapings struct {
XMLName xml.Name `xml:"osm"`
Node []Nodes `xml:"node"`
//Ways []Way `xml:"way"`
//Lat string `xml:"way"`
}
type Nodes struct {
XMLName xml.Name `xml:"node"`
Lat string `xml:"lat,attr"`
Lon string `xml:"lon,attr"`
}
/*type Way struct {
XMLName xml.Name `xml:"way"`
Nods string `xml:"nd"`
Tags string `xml:"tag"`
}*/
func main() {
xmlFile, err := os.Open("map1.osm")
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened map1.osm")
// defer the closing of our xmlFile so that we can parse it later on
defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile)
var mapings Mapings
xml.Unmarshal(byteValue, &mapings)
fmt.Println(len(mapings.Mapings))
/*for i := 0; i < len(maping.Map1); i++ {
fmt.Println("User Type: " + maping.Map1[i])
}*/
}
xml (map1.osm):
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.6.0 (20823 thorn-01.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node id="314438086" visible="true" version="1" changeset="788811" timestamp="2008-11-24T21:48:15Z" user="Golovco Anatolie" uid="28068" lat="46.5481066" lon="29.8918966"/>
<node id="314438088" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:13Z" user="Jekader" uid="48157" lat="46.5490165" lon="29.8984909"/>
<node id="314438090" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:14Z" user="Jekader" uid="48157" lat="46.5501184" lon="29.9068664"/>
<node id="314438092" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:14Z" user="Jekader" uid="48157" lat="46.5513771" lon="29.9158444"/>
<node id="314438094" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:14Z" user="Jekader" uid="48157" lat="46.5526388" lon="29.9241189"/>
<node id="314438096" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:14Z" user="Jekader" uid="48157" lat="46.5547187" lon="29.9425626"/>
<node id="314438098" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:14Z" user="Jekader" uid="48157" lat="46.5555938" lon="29.9450053"/>
<node id="314438101" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:15Z" user="Jekader" uid="48157" lat="46.5569836" lon="29.9450036"/>
<node id="314438103" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:15Z" user="Jekader" uid="48157" lat="46.5581351" lon="29.9454019"/>
<node id="314438105" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:16Z" user="Jekader" uid="48157" lat="46.5592587" lon="29.9469649"/>
<node id="314438107" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:16Z" user="Jekader" uid="48157" lat="46.5600734" lon="29.9483582"/>
<node id="314438109" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:16Z" user="Jekader" uid="48157" lat="46.5609106" lon="29.9487314"/>
<node id="314438112" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:17Z" user="Jekader" uid="48157" lat="46.5613780" lon="29.9483331"/>
<node id="314438114" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:17Z" user="Jekader" uid="48157" lat="46.5612033" lon="29.9475474"/>
<node id="314438116" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:17Z" user="Jekader" uid="48157" lat="46.5606102" lon="29.9461379"/>
<node id="314438119" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:17Z" user="Jekader" uid="48157" lat="46.5599122" lon="29.9450592"/>
<node id="314438121" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:18Z" user="Jekader" uid="48157" lat="46.5596347" lon="29.9444609"/>
<node id="314438123" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:18Z" user="Jekader" uid="48157" lat="46.5592856" lon="29.9432948"/>
<node id="314438125" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:18Z" user="Jekader" uid="48157" lat="46.5589586" lon="29.9418237"/>
<node id="314438127" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:18Z" user="Jekader" uid="48157" lat="46.5589541" lon="29.9407494"/>
<node id="314438129" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:19Z" user="Jekader" uid="48157" lat="46.5594955" lon="29.9400337"/>
<node id="314438132" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:19Z" user="Jekader" uid="48157" lat="46.5604272" lon="29.9410528"/>
<node id="314438134" visible="true" version="2" changeset="2685141" timestamp="2009-09-30T08:39:19Z" user="Jekader" uid="48157" lat="46.5613887" lon="29.9419047"/>
<way id="100667322" visible="true" version="8" changeset="50998563" timestamp="2017-08-10T11:23:49Z" user="Maturi0n" uid="2052948">
<nd ref="1159737503"/>
<nd ref="5026253428"/>
<nd ref="4055301339"/>
<nd ref="4055301338"/>
<nd ref="1159737548"/>
<tag k="highway" v="residential"/>
<tag k="surface" v="paved"/>
</way>
<way id="100667887" visible="true" version="2" changeset="57044823" timestamp="2018-03-09T21:12:36Z" user="Maturi0n" uid="2052948">
<nd ref="1163803036"/>
<nd ref="5468161794"/>
<nd ref="1163803038"/>
<nd ref="1163803040"/>
<nd ref="1163803045"/>
<nd ref="1163803029"/>
<nd ref="1163803034"/>
<nd ref="1159938017"/>
<tag k="highway" v="residential"/>
</way>
<way id="100667889" visible="true" version="7" changeset="52458354" timestamp="2017-09-28T21:13:28Z" user="Maturi0n" uid="2052948">
<nd ref="1159939213"/>
<nd ref="1159939240"/>
<nd ref="1159936620"/>
<nd ref="1159940574"/>
<nd ref="5136216695"/>
<nd ref="1159936204"/>
<nd ref="1159935607"/>
<tag k="highway" v="residential"/>
<tag k="name" v="улица Островского"/>
<tag k="name:de" v="uliza Ostrowskogo"/>
<tag k="name:en" v="Ostrovskogo Street"/>
<tag k="name:md" v="Страда Островский"/>
<tag k="name:ro" v="Strada Ostrovski"/>
<tag k="name:ru" v="улица Островского"/>
<tag k="name:uk" v="вулиця Островського"/>
</way>
</osm>
ответ:
# command-line-arguments
.\main2.go:46:25: mapings.Mapings undefined (type Mapings has no field or method Mapings)
скопировал пример нет ошибки, мой изменения суть не меняет, и в чем жэ моя ощибка?