KML layer not able to parse KML return data

1025
10
11-30-2010 01:24 AM
BjørnarSundsbø
Occasional Contributor
I'm trying to use the KmlLayer against http://wms.met.no/googleearth/metno.kml but get the following exception.

Unhandeled exception System.Xml.XmlException: Invalid character in the given encoding. Line 48, position 16.


I'm using version 2.1 RC of the API. The Toolkit.DataSources source available on codeplex does not include this class, so I'm not able to debug it.

Anyone who is able to make this service work, or provide any information on a fix?
0 Kudos
10 Replies
TonyBacon
New Contributor II
I am experiencing the same thing. Wonder if you ever found a solution?

It seems to be a timing/timeout issue for me. Watching in fiddler I notice that the error occurs before the httprequest has completed.
0 Kudos
TonyBacon
New Contributor II
My bad. I had neglected a reference to the toolkit datasources library. Now that I have added that and coincidentally also upgraded to the 2.2 release of hte SL api, I am able to access some kml files. I have not however suceeded in accessing kmz files. I unzipped one particular kmz file to get at the kml file it contained and could not get the kmllayer to work with that either.
0 Kudos
DanielWalton
Occasional Contributor
That KML file has unicode characters in it. the KmlLayer class for Silverlight opens the files with UTF-8 encoding. If you encounter characters that aren't valid for UTF8 the parser will blow up.
0 Kudos
BjørnarSundsbø
Occasional Contributor
Apparently I have not been notified when this thread was replied to. I've updated to version 2.2, but the same problem still persists.

Is there any way to tell the system to use unicode encoding, in much the same way as you can with setting the culture for the thread? For some reason I doubt it, though it is worth asking anyway.

I will see what the beta for 3.0 can handle, as I don't feel like digging too deep into this right now. It would be very cool to get this working
0 Kudos
DanielWalton
Occasional Contributor
You can download the source for KmlLayer here and tinker with it.
0 Kudos
BjørnarSundsbø
Occasional Contributor
You can download the source for KmlLayer here and tinker with it.


Already done so 😄
0 Kudos
BjørnarSundsbø
Occasional Contributor
To anyone from the ESRI team:

Seems like a few sources for KML have declared the encoding of the document to be different that what it actually is. When we don't have control of the source, it would be helpful if the KmlLayer could deal with this. The url in the first post is one such as this.

Is this something that can be taken care of for the next release?
0 Kudos
BjørnarSundsbø
Occasional Contributor
The following code in the else statement of the SetSource method did the trick:
StreamReader streamReader = new StreamReader(seekableStream);
string xml = streamReader.ReadToEnd();

 xLocalDoc = XDocument.Load(
#if SILVERLIGHT
 seekableStream
#else
 XmlReader.Create(new StringReader(xml))
#endif
, LoadOptions.None);


I hope this can be added to the next version.

The remaining problem seems to be that all graphics are placed more or less at lat/lon 0 (off the coast a little west of Gabon), though that is not the location of at least many of the features in the KML. Just started looking in to that.
0 Kudos
TonyBacon
New Contributor II
Bjonar, have you been able to work with kmz files? Most of the kml data that I hope to use in our map is compressed as kmz.
0 Kudos