标签云

微信群

扫码加入我们

WeChat QR Code

I'm trying to import a mkl file with jak but i get the following error:javax.xml.bind.UnmarshalException: unexpected element (uri:"http://earth.google.com/kml/2.2", local:"kml"). Expected elements are ... and then a big listDoes anyone else run into this problem?This is the code:final Kml kml = Kml.unmarshal(new File("../data/Eemskanaal.kml"));final Placemark placemark = (Placemark) kml.getFeature();Point point = (Point) placemark.getGeometry();List<Coordinate> coordinates = point.getCoordinates();for (Coordinate coordinate : coordinates) {System.out.println(coordinate.getLatitude());System.out.println(coordinate.getLongitude());System.out.println(coordinate.getAltitude());}And this is the kml file:<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.2"><Document><name>BU00100107 Verspreide huizen Eemskanaal (ten zuiden)</name><description><![CDATA[description]]></description><Placemark><name>BLA!</name><description><![CDATA[]]></description><styleUrl>#style1</styleUrl><Polygon><outerBoundaryIs><LinearRing><tessellate>1</tessellate><coordinates>6.941796,53.314914,0.0000006.942705,53.310923,0.0000006.952713,53.305394,0.0000006.954853,53.300262,0.0000006.954239,53.296317,0.0000006.962271,53.295483,0.0000006.995900,53.287338,0.0000006.995013,53.285264,0.0000006.996842,53.281429,0.0000006.991748,53.278255,0.0000006.990729,53.275234,0.0000006.988361,53.274477,0.0000006.990120,53.271780,0.0000006.984540,53.272709,0.0000006.984543,53.274393,0.0000006.980317,53.274404,0.0000006.975829,53.272503,0.0000006.974816,53.271125,0.0000006.963342,53.271937,0.0000006.955082,53.265909,0.0000006.945183,53.269634,0.0000006.940684,53.273351,0.0000006.935942,53.273875,0.0000006.934392,53.276351,0.0000006.929104,53.272181,0.0000006.909544,53.265952,0.0000006.908803,53.269015,0.0000006.909151,53.278897,0.0000006.888166,53.279161,0.0000006.887788,53.279639,0.0000006.886750,53.280950,0.0000006.886729,53.280977,0.0000006.888260,53.281856,0.0000006.895912,53.286254,0.0000006.892976,53.288089,0.0000006.891571,53.290803,0.0000006.887323,53.298046,0.0000006.887729,53.309725,0.0000006.887583,53.309816,0.0000006.888683,53.311891,0.0000006.893966,53.313119,0.0000006.924732,53.311548,0.0000006.929655,53.312392,0.0000006.934810,53.315353,0.0000006.941796,53.314914,0.000000</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><tessellate>1</tessellate><coordinates>6.905549,53.283453,0.0000006.908790,53.282516,0.0000006.912146,53.283305,0.0000006.916480,53.287575,0.0000006.916764,53.288072,0.0000006.915251,53.288369,0.0000006.915097,53.290097,0.0000006.912526,53.292361,0.0000006.908052,53.290971,0.0000006.905569,53.288875,0.0000006.905549,53.283453,0.000000</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark></Document></kml>Any other solutions are also welcome


nice clever solution

2019年04月18日33分16秒

I know it's wrong but i didn't make the files and i have more then 1700 of them... What do you use instead of jak?

2019年04月19日33分16秒

I'm not actually a Java guy really, but you could use the Java XML libraries to pre-process an XML doc, check the namespace and change it if necessary before handing it off to Jak.

1970年01月01日00分03秒

i looked at jaxb which looks good, but it's quite complex to start with since my school assignments aren't that long.

2019年04月19日33分16秒

Yeah, Jaxb is heavyweight. Here's a couple of options: Just use DOM parsing, something like this: java-samples.com/showtutorial.php?tutorialid=152. Or, easier, read the file in as text and do a regex to find earth.google.com/kml/2.2 and change it to the right namespace. Then save it and re-process it using Jak

2019年04月18日33分16秒