c# - OpenStreetMap XML to Object -
I have at least XML that I want to get the specific code from using XDocument Like Maxspeed
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Osm version = "0.6" generator = "overpass API" & gt; & Lt; Meta osm_base = "2015-01-15T20: 26: 03Z" /> & Lt; Node id = "1312239864" late = "50.5348877" lon = "5.6286790" & gt; & Lt; Tag k = "highway" v = "crossing" /> & Lt; Tag k = "traffic_calming" v = "bump" /> & Lt; / Node & gt; & Lt; Node id = "2025084665" late = "50.5345623" lon = "5.6274183" & gt; & Lt; Tag k = "traffic_calming" v = "chocal" /> & Lt; / Node & gt; & Lt; Node id = "2025084669" late = "50.5353414" lon = "5.6303289" /> & lt; Method id = "191950462" & gt; & Lt; Nd ref = "2025084665" /> & Lt; Tag k = "bicycle" v = "yes" /> & Lt; Tag k = "highway" v = "secondary" /> & Lt; Tag k = "maxspeed" v = "30" /> & Lt; Tag k = "name" v = "rue d'esneux" /> & Lt; Tag k = "source: maxspeed" v = "school area" /> & Lt; / Way & gt; & Lt; / Osm & gt; I have tried it
way.Tags = (list & lt; OSMTag> (doc.Descendants ("tag"). Select (c => New OSMTAG () {key = C. Attribute ("of"). Value, value = c. Attribute ("V"). Value}}); public class OSMway {public OSMWE}}
but I get an invalid cast exception.
Public listing & lt; OSMTag & gt; Tags {get; Set; }} Public class OSMTag {public OSMTag () {} Public OSMTag (string key, string value) {key = key; Value = value; } Public string key {get; Set; } Public string value {get; Set; }}
You get an IEnumerable back:
< Code> route.tags = doctors Discendants ("tags"). Select (C => New OSMTag () {key = C attribute ("of"). Value, value = C. attribute ("V") value}}.) To create list (); A list must be applied to IEnumerable but each IEnumerable is not a list. ToList () extension converts an IEnumerable to a list
Comments
Post a Comment