This project has moved. For the latest updates, please go here.

Awesome Tool! - Need a little help opening KMZ Archive

Mar 7, 2016 at 1:09 PM
Thank you for the awesome work done in SharpKML.

I am trying to extract the KML file within a KMZ archive and suspect I am missing a simple step. I've looked through the forum and also read the documentation about the changes made to the KML-KMZ libraries about loading KMZ files. The KMZ file I am attempting to load is from the National Weather Service Radar groundoverlays. There is only one kml file inside named doc.kml with the following header.

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="">

I am using the pre-compiled SharpKMZ libraries.

Here is the code I am having problems with...

KmlFile myKmlFile;
using (FileStream myFileStream = new FileStream(Application.StartupPath.ToString() + "\MPX_Radar_data.kmz", FileMode.Open))
            KmzFile myKmz = KmzFile.Open(myFileStream);
            myKmlFile = myKmz.GetDefaultKmlFile();

        Kml kml = myKmlFile.Root as Kml;
Problem is that "myKmlFile" root is null. However the output of myKmz.ReadKml() shows the contents of the doc.kml. I must be missing something.
Mar 7, 2016 at 8:22 PM
It looks like it might be because the KML is using an obsolete namespace. You might be able to work around that by parsing the string yourself, something like this should work:
    Kml kml;
    using (FileStream myFileStream = new FileStream(...))
        KmzFile myKmz = KmzFile.Open(myFileStream);

        var parser = new Parser();
        parser.ParseString(myKmz.ReadKml(), namespaces: false);
        kml = parser.Root as Kml;
Hope it helps,
Mar 8, 2016 at 5:00 PM
I will give it a try! Thanks!