MapAround.Mapping.MapWorkspace.getXml C# (CSharp) Method

getXml() private method

private getXml ( ) : string
return string
        private string getXml()
        {
            CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
            ci.NumberFormat.NumberDecimalSeparator = ".";
            XmlDocument doc = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", Encoding.UTF8.WebName, null);

            XmlElement root = doc.DocumentElement;
            doc.InsertBefore(declaration, root);

            // --------- корень
            XmlElement workspaceRoot = doc.CreateElement("map_workspace");
            doc.AppendChild(workspaceRoot);

            addAttribute(doc, workspaceRoot, "version", "1.0");

            // --------- просмотр
            XmlElement viewBoxElement = doc.CreateElement("view_box");
            workspaceRoot.AppendChild(viewBoxElement);

            addAttribute(doc, viewBoxElement, "min_x", _viewBox.IsEmpty() ? string.Empty : _viewBox.MinX.ToString(ci));
            addAttribute(doc, viewBoxElement, "min_y", _viewBox.IsEmpty() ? string.Empty : _viewBox.MinY.ToString(ci));
            addAttribute(doc, viewBoxElement, "max_x", _viewBox.IsEmpty() ? string.Empty : _viewBox.MaxX.ToString(ci));
            addAttribute(doc, viewBoxElement, "max_y", _viewBox.IsEmpty() ? string.Empty : _viewBox.MaxY.ToString(ci));

            // --------- карта
            XmlElement mapElement = doc.CreateElement("map");
            workspaceRoot.AppendChild(mapElement);

            addAttribute(doc, mapElement, "title", _map.Title);
            addAttribute(doc, mapElement, "description", _map.Description);
            addAttribute(doc, mapElement, "antialias", _map.RenderingSettings.AntiAliasGeometry ? "1" : "0");
            addAttribute(doc, mapElement, "text_antialias", _map.RenderingSettings.AntiAliasText ? "1" : "0");
            addAttribute(doc, mapElement, "coordinate_system_wkt", _map.CoodrinateSystemWKT);

            if (!string.IsNullOrEmpty(_map.ApplicationXmlData))
            {
                XmlElement appData = doc.CreateElement("application_data");
                appData.InnerXml = _map.ApplicationXmlData;
                mapElement.AppendChild(appData);
            }

            //addAttribute(doc, mapElement, "use_transform_from_coordinate_system", "1");

            // --------- растр
            XmlElement rasterElement = doc.CreateElement("raster");
            mapElement.AppendChild(rasterElement);
            addAttribute(doc, rasterElement, "file_name", this.RasterFileName);

            addAttribute(doc, rasterElement, "min_x", _map.CosmeticRaster.Bounds.MinX.ToString(ci));
            addAttribute(doc, rasterElement, "min_y", _map.CosmeticRaster.Bounds.MinY.ToString(ci));
            addAttribute(doc, rasterElement, "max_x", _map.CosmeticRaster.Bounds.MaxX.ToString(ci));
            addAttribute(doc, rasterElement, "max_y", _map.CosmeticRaster.Bounds.MaxY.ToString(ci));
            addAttribute(doc, rasterElement, "visible", _map.CosmeticRaster.Visible ? "1" : "0");
            addAttribute(doc, rasterElement, "interpolation", ((int)_map.CosmeticRaster.InterpolationMode).ToString());


            // --------- слои
            XmlElement layersElement = doc.CreateElement("layers");
            mapElement.AppendChild(layersElement);

            foreach (LayerBase l in _map.Layers)
                addLayerElement(l, doc, layersElement);

            //using (MemoryStream ms = new MemoryStream())
            //{
            //    doc.Save(ms);
            //    UTF8Encoding utf8 = new UTF8Encoding();
            //    string s = utf8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
            //    return s;
            //}

            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);
            xw.Formatting = Formatting.Indented;
            doc.WriteTo(xw);
            return sw.ToString();
        }