Skip navigation links
NASA WorldWind-CE

Package gov.nasa.worldwind.ogc.kml

Provides classes for parsing KML and KMZ files and streams.

See: Description

Package gov.nasa.worldwind.ogc.kml Description

Provides classes for parsing KML and KMZ files and streams.

How to Parse a KML or KMZ File or Stream

  1. Create a KMLRoot via one of its constructors, such as KMLRoot.KMLRoot(java.io.File), passing the KML or KMZ source to the constructor. A KMLRoot provides access to the KML contents. The source can be either a file, an input stream or a URL.
  2. Call KMLRoot.parse(Object[]) to parse the document.
  3. The KMLRoot class provides accessor methods for the kml element of the KML file, its root. The content includes the element's single attribute, hint, and the NetworkLinkControl and Feature elements it may contain. Once the root is parsed, use these methods to obtain objects representing these elements, and use the accessor methods of those objects in turn to obtain their contents.
  4. Each KML element defined in the KML specification has a corresponding class provided in this package. Each of those classes contains methods to obtain the element's contents as defined by the specification. The same is true for the other specifications KML uses: Atom, XAL and the GX extensions defined by Google. Use these classes to obtain the contents of individual elements of the KML file.
The classes in this package only read and parse a KML file. Mapping them to shapes, annotations and other WorldWind objects is a separate step. WorldWind provides default mappings for many KML elements, but an application is fully able to provide its own, and in some cases is expected to.

Extending the Classes

This package's classes are designed for easy behavior modification and replacement, and for straightforward addition of operations to be performed during parsing. See the description of AbstractXMLEventParser for further information.

Relative References

Because the KML specification requires relative references within KML files to be resolved relative to the location of the file, a context is provided to resolve these references. The context is specific to the document type — file, stream, KML or KMZ — and is provided by the KMLDoc interface and its implementing classes. It's available from the KMLRoot. See the description of the KMLDoc interface for further information.

Skip navigation links
NASA WorldWind-CE