This project has moved and is read-only. For the latest updates, please go here.

Multiple links

Jun 6, 2011 at 5:35 PM

Hi there

You library looks nice and tidy. I am looking for some advanced examples if you have any. 

I am specifically looking for this type of structure:

Main KML points to many links

Each link has many real time updated or added placemarks.

I do not see how to add multiple links to a kml file(or even one for that matter)?

I am still learning KML and it's rules so maybe what I am trying to do is not allowed.


Thanks in advance!

Jun 7, 2011 at 12:40 AM

I think what you're trying to achieve is something like the example given here. The Link must be contained by a NetworkLink, which in turn is contained by a Container. If you use a Document then you can group together more than one Feature (NetworkLink derives from Feature) so you could do something like this in code:

using System;
using SharpKml.Base;
using SharpKml.Dom;
using SharpKml.Engine;

class Program
    static void Main(string[] args)
        NetworkLink networkLink = new NetworkLink();
        networkLink.Link = new Link();
        networkLink.Link.Href = new Uri("");

        Document document = new Document();

        Kml root = new Kml();
        root.Feature = document;

        Serializer serializer = new Serializer();

Which outputs:

<?xml version="1.0" encoding="utf-16"?>
<kml xmlns="">

As for processing the updates (i.e. changing the KML), once you've built your Update object and loaded that then you can use the Process extension method in the SharpKml.Engine namespace to add/delete/replace parts of your original KML.

Hope that gives you a start in the right direction but if you have any problems then please reply below.

Thanks for trying the library and your feedback,


Jun 7, 2011 at 4:29 PM

Wonderful post. Can't wait to get this in and I am not sure how I did not realize that a NetworkLink derived from feature. Thanks so much!!

Jun 7, 2011 at 11:42 PM

You raise a good point; there are a lot of classes in the library so it's not always obvious what they inherit.

As I'm just a hobby developer I only have the express edition of Visual Studio so can't generate a class diagram, but there is a basic diagram on the KML Reference page (I've updated the Documentation page of this project to include a link to it too); if I get time I'll look at updating the documentation to include a class diagram of this library to make it easier in the future.


Jun 8, 2011 at 12:47 AM

Ok. So far so good.


One more thing, can you point me to documentation on using your StyleUrl type? No matter what I do I cannot get a properly formatted URI created to feed it. I expect to be able to provide #whatever. That's is not a URI. Is your type wrong?


See iconstyle element here:

Jun 8, 2011 at 4:52 AM

The Uri class used in the library is the one provided by the .NET framework. I think the problem you might be having is that by default it will try to create an absolute reference, however, there is an overloaded constructor which should help:

IconStyle iconStyle = new IconStyle();
iconStyle.Icon = new IconStyle.IconLink(new Uri("#whatever", UriKind.Relative));