Пример #1
0
        /// <summary>
        /// Loads a KmlFile using the specified KML data.
        /// </summary>
        /// <param name="reader">The text reader containing the KML data.</param>
        /// <returns>A KmlFile representing the specified information.</returns>
        /// <remarks>
        /// This method checks for duplicate Id's in the file and throws an
        /// exception if duplicate Id's are found. To enable duplicate Id's
        /// use the <see cref="Parser"/> class and pass the root element
        /// to <see cref="Create"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">reader is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// Duplicate Id's were found or the XML is nested too deeply.
        /// </exception>
        /// <exception cref="System.Xml.XmlException">
        /// An error occurred while parsing the KML.
        /// </exception>
        public static KmlFile Load(TextReader reader)
        {
            Check.IsNotNull(reader, nameof(reader));

            var file = new KmlFile();

            file.Parse(reader);
            return(file);
        }
Пример #2
0
        /// <summary>
        /// Loads a KmlFile using the specified KML data.
        /// </summary>
        /// <param name="reader">The text reader containing the KML data.</param>
        /// <returns>A KmlFile representing the specified information.</returns>
        /// <remarks>
        /// This method checks for duplicate Id's in the file and throws an
        /// exception if duplicate Id's are found. To enable duplicate Id's
        /// use the <see cref="Parser"/> class and pass the root element
        /// to <see cref="Create"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">reader is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// Duplicate Id's were found or the XML is nested too deeply.
        /// </exception>
        /// <exception cref="System.Xml.XmlException">
        /// An error occurred while parsing the KML.
        /// </exception>
        public static KmlFile Load(TextReader reader, bool namespaces = true)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            KmlFile file = new KmlFile();

            file.Parse(reader, namespaces);
            return(file);
        }
Пример #3
0
        /// <summary>
        /// Loads a KmlFile using the specified KML data.
        /// </summary>
        /// <param name="reader">The text reader containing the KML data.</param>
        /// <returns>A KmlFile representing the specified information.</returns>
        /// <remarks>
        /// This method checks for duplicate Id's in the file and throws an
        /// exception if duplicate Id's are found. To enable duplicate Id's
        /// use the <see cref="Parser"/> class and pass the root element
        /// to <see cref="Create"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">reader is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// Duplicate Id's were found or the XML is nested too deeply.
        /// </exception>
        /// <exception cref="System.Xml.XmlException">
        /// An error occurred while parsing the KML.
        /// </exception>
        public static KmlFile Load(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var file = new KmlFile();

            file.Parse(reader);
            return(file);
        }
Пример #4
0
        /// <summary>
        /// Loads a KmlFile using the specified KML data.
        /// </summary>
        /// <param name="input">The stream containing the KML data.</param>
        /// <returns>A KmlFile representing the specified information.</returns>
        /// <remarks>
        /// This method checks for duplicate Id's in the file and throws an
        /// exception if duplicate Id's are found. To enable duplicate Id's
        /// use the <see cref="Parser"/> class and pass the root element
        /// to <see cref="Create"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">input is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// Duplicate Id's were found or the XML is nested too deeply.
        /// </exception>
        /// <exception cref="IOException">An I/O error occurred.</exception>
        /// <exception cref="NotSupportedException">
        /// The stream does not support reading.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The stream was closed.
        /// </exception>
        /// <exception cref="System.Xml.XmlException">
        /// An error occurred while parsing the KML.
        /// </exception>
        public static KmlFile Load(Stream input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            KmlFile file = new KmlFile();

            using (var reader = new StreamReader(input))
            {
                file.Parse(reader);
            }
            return(file);
        }
Пример #5
0
        /// <summary>
        /// Loads a KmlFile using the specified KMZ data.
        /// </summary>
        /// <param name="kmz">The KmzFile containing the KML data.</param>
        /// <param name="namespaces">true to allow namespace support; false to ignore namespaces.</param>
        /// <returns>
        /// A KmlFile representing the default KML file in the specified KMZ archive
        /// or null if no KML data was found.
        /// </returns>
        /// <remarks>
        /// This method checks for duplicate Id's in the file and throws an
        /// exception if duplicate Id's are found. To enable duplicate Id's
        /// use the <see cref="Parser"/> class and pass the root element
        /// to <see cref="Create"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">kmz is null.</exception>
        /// <exception cref="ObjectDisposedException">
        /// <see cref="KmzFile.Dispose"/> has been called on kmz.
        /// </exception>
        /// <exception cref="System.Xml.XmlException">
        /// An error occurred while parsing the KML.
        /// </exception>
        public static KmlFile LoadFromKmz(IKmzReader kmz, bool namespaces = true)
        {
            if (kmz == null)
            {
                throw new ArgumentNullException("kmz");
            }

            string kml = kmz.ReadKml();

            if (kml != null)
            {
                KmlFile instance = new KmlFile();
                using (var stream = new StringReader(kml))
                {
                    instance.Parse(stream, namespaces);
                }
                return(instance);
            }
            return(null);
        }
Пример #6
0
        /// <summary>
        /// Loads a KmlFile using the specified KMZ data.
        /// </summary>
        /// <param name="kmz">The KmzFile containing the KML data.</param>
        /// <returns>
        /// A KmlFile representing the default KML file in the specified KMZ archive
        /// or null if no KML data was found.
        /// </returns>
        /// <remarks>
        /// This method checks for duplicate Id's in the file and throws an
        /// exception if duplicate Id's are found. To enable duplicate Id's
        /// use the <see cref="Parser"/> class and pass the root element
        /// to <see cref="Create"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">kmz is null.</exception>
        /// <exception cref="ObjectDisposedException">
        /// <see cref="KmzFile.Dispose"/> has been called on kmz.
        /// </exception>
        /// <exception cref="System.Xml.XmlException">
        /// An error occurred while parsing the KML.
        /// </exception>
        public static KmlFile LoadFromKmz(KmzFile kmz)
        {
            if (kmz == null)
            {
                throw new ArgumentNullException("kmz");
            }

            string kml = kmz.ReadKml();

            if (kml != null)
            {
                KmlFile instance = new KmlFile();
                using (var stream = new StringReader(kml))
                {
                    instance.Parse(stream);
                }
                return(instance);
            }
            return(null);
        }