Question

I recently came across a KML file that had a <Document> inside a <Document> (Actually a Document inside a Folder inside the root Document). Since a Document is a Feature this seems to be valid, but is this semantically acceptable? I am parsing KML in my app, should I accept it or reject it?

Was it helpful?

Solution

Both the Document and Folder elements in KML are container types and it is perfectly valid to have a Document inside a Document, Document inside a Folder, Folder inside a Document, etc. In nearly all cases the Folder and Document can be used interchangeably.

Conceptually it makes sense for "Folders" to have "Documents" inside them but there is no such restriction with KML Folders or Documents. The only semantic difference between a Document and a Folder within the KML 2.2 Specification is that only the Document can have a Schema element or Shared Styles as child elements and the Folder cannot. Other than this the Folder and Document are the same.

Here's the syntax summary description of "Folder" and "Document" elements from KML Reference:

<Folder id="ID">
  <!-- inherited from Feature element -->
  <name>...</name>                      <!-- string -->
  ...
  <ExtendedData>...</ExtendedData>
  <!-- specific to Folder -->
  <!-- 0 or more Feature elements -->
</Folder>

<Document id="ID">
  <!-- inherited from Feature element -->
  <name>...</name>                      <!-- string -->
  ...
  <ExtendedData>...</ExtendedData>
  <!-- specific to Document -->
  <!-- 0 or more Schema elements -->
  <!-- 0 or more Feature elements -->
</Document>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top