sharpkml
sharpkml copied to clipboard
No children?
I need to traverse the DOM created by importing a KML file. In my case I have a hierarchy of folders that needs to be maintained. However, SharpKml appears only to support "Flatten" as a way to access the child elements. In fact, "element.Children" always returns an empty set. Is this a shortcoming of SharpKml (missing feature), or am I doing something wrong?
Thanks!
Thanks for using the library, sorry to hear it's not as easy to use as could be.
The Children property is a way to access unknown elements discovered during parsing, as we have to maintain them when saving the data again. This would explain why it's empty - it means all the elements were understood (which is a good thing 🙂). The idea of the library is to provide a strong wrapper around the underlying KML (which is a subset of XML), so not all the XML conventions are maintained (i.e. the way you describe of navigating the children is typical when navigating XML nodes).
Therefore, if you're interested in all the folders then the Flatten method would be the way to extract them. If you know the structure of the file, then you could try accessing the various properties to search for the elements you're after (e.g. ((Folder)Kml.Feature).Features)
Hope that gives a brief overview of why it is the way it is; if you have a specific scenario in mind, I can try to update the documentation to help.
Err.. I hit the same problem, but what if I don't want to flatten the children?
I want to take a look at each level of the hierarchy, level by level. Or am I just misunderstanding KML?