 
     private static function layerToXML(layer:Layer, label:String):XML
     {
-        var lyrXML:XML;
+        var layerXML:XML;
 
         if (layer is ArcGISDynamicMapServiceLayer)
         {
-            var dynLyr:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
-            lyrXML = <layer label={label}
+            var dynLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
+
+            layerXML = <layer label={label}
                     type="dynamic"
-                    visible={dynLyr.visible}
-                    alpha={dynLyr.alpha}
-                    url={dynLyr.url}
-                    useproxy={dynLyr.proxyURL != null}/>;
-            if (dynLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(dynLyr.refreshInterval);
-            }
-            if (dynLyr.showInLegend)
-            {
-                if (dynLyr.showInLegendHiddenLayers)
-                {
-                    lyrXML.@showinlegendhiddenlayers = dynLyr.showInLegendHiddenLayers.join();
+                    visible={dynLayer.visible}
+                    alpha={dynLayer.alpha}
+                    url={dynLayer.url}
+                    useproxy={dynLayer.proxyURL != null}/>;
+
+            if (dynLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(dynLayer.refreshInterval);
+            }
+
+            if (dynLayer.showInLegend)
+            {
+                if (dynLayer.showInLegendHiddenLayers)
+                {
+                    layerXML.@showinlegendhiddenlayers = dynLayer.showInLegendHiddenLayers.join();
                 }
             }
             else
             {
-                lyrXML.@showinlegend = false;
-            }
-            if (dynLyr.visibleLayers)
-            {
-                lyrXML.@visiblelayers = dynLyr.visibleLayers.toArray().join();
-            }
-            if (dynLyr.layerDefinitions && dynLyr.layerDefinitions.length > 0)
+                layerXML.@showinlegend = false;
+            }
+
+            if (dynLayer.visibleLayers)
+            {
+                layerXML.@visiblelayers = dynLayer.visibleLayers.toArray().join();
+            }
+
+            if (dynLayer.layerDefinitions && dynLayer.layerDefinitions.length > 0)
             {
                 // <sublayer id="2" definitionexpression="AGBUR = 'BIA'"/>
-                for each (var layerDefinition:LayerDefinition in dynLyr.layerDefinitions)
-                {
-                    lyrXML.appendChild(<sublayer id={layerDefinition.layerId} definitionexpression={layerDefinition.definition}/>);
+                for each (var layerDefinition:LayerDefinition in dynLayer.layerDefinitions)
+                {
+                    layerXML.appendChild(<sublayer id={layerDefinition.layerId} definitionexpression={layerDefinition.definition}/>);
                 }
             }
         }
         else if (layer is ArcGISImageServiceLayer)
         {
-            var imgLyr:ArcGISImageServiceLayer = layer as ArcGISImageServiceLayer;
-            lyrXML = <layer label={label}
+            var imgLayer:ArcGISImageServiceLayer = layer as ArcGISImageServiceLayer;
+
+            layerXML = <layer label={label}
                     type="image"
-                    visible={imgLyr.visible}
-                    alpha={imgLyr.alpha}
-                    url={imgLyr.url}
-                    useproxy={imgLyr.proxyURL != null}/>;
-            if (imgLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(imgLyr.refreshInterval);
-            }
-            if (!imgLyr.showInLegend)
-            {
-                lyrXML.@showinlegend = false;
-            }
-            if (imgLyr.bandIds)
-            {
-                lyrXML.@bandids = imgLyr.bandIds.join();
+                    visible={imgLayer.visible}
+                    alpha={imgLayer.alpha}
+                    url={imgLayer.url}
+                    useproxy={imgLayer.proxyURL != null}/>;
+
+            if (imgLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(imgLayer.refreshInterval);
+            }
+
+            if (!imgLayer.showInLegend)
+            {
+                layerXML.@showinlegend = false;
+            }
+
+            if (imgLayer.bandIds)
+            {
+                layerXML.@bandids = imgLayer.bandIds.join();
             }
         }
         else if (layer is ArcGISTiledMapServiceLayer)
         {
-            var tiledLyr:ArcGISTiledMapServiceLayer = layer as ArcGISTiledMapServiceLayer;
-            lyrXML = <layer label={label}
+            var tiledLayer:ArcGISTiledMapServiceLayer = layer as ArcGISTiledMapServiceLayer;
+            layerXML = <layer label={label}
                     type="tiled"
-                    visible={tiledLyr.visible}
-                    alpha={tiledLyr.alpha}
-                    url={tiledLyr.url}
-                    useproxy={tiledLyr.proxyURL != null}/>;
-            if (tiledLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(tiledLyr.refreshInterval);
-            }
-            if (tiledLyr.showInLegend)
-            {
-                if (tiledLyr.showInLegendHiddenLayers)
-                {
-                    lyrXML.@showinlegendhiddenlayers = tiledLyr.showInLegendHiddenLayers.join();
+                    visible={tiledLayer.visible}
+                    alpha={tiledLayer.alpha}
+                    url={tiledLayer.url}
+                    useproxy={tiledLayer.proxyURL != null}/>;
+
+            if (tiledLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(tiledLayer.refreshInterval);
+            }
+
+            if (tiledLayer.showInLegend)
+            {
+                if (tiledLayer.showInLegendHiddenLayers)
+                {
+                    layerXML.@showinlegendhiddenlayers = tiledLayer.showInLegendHiddenLayers.join();
                 }
             }
             else
             {
-                lyrXML.@showinlegend = false;
-            }
-            if (tiledLyr.displayLevels)
-            {
-                lyrXML.@displaylevels = tiledLyr.displayLevels.join();
+                layerXML.@showinlegend = false;
+            }
+
+            if (tiledLayer.displayLevels)
+            {
+                layerXML.@displaylevels = tiledLayer.displayLevels.join();
             }
         }
         else if (layer is CSVLayer)
         {
-            var csvLyr:CSVLayer = layer as CSVLayer;
-            lyrXML = <layer label={label}
+            var csvLayer:CSVLayer = layer as CSVLayer;
+
+            layerXML = <layer label={label}
                     type="csv"
-                    visible={csvLyr.visible}
-                    alpha={csvLyr.alpha}
-                    url={csvLyr.url}
-                    longitudefieldname={csvLyr.longitudeFieldName}
-                    latitudefieldname={csvLyr.latitudeFieldName}/>;
-            if (csvLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(csvLyr.refreshInterval);
-            }
-            if (!csvLyr.showInLegend)
-            {
-                lyrXML.@showinlegend = false;
-            }
-            if (csvLyr.columnDelimiter != ",")
-            {
-                lyrXML.@columndelimiter = csvLyr.columnDelimiter;
-            }
-            if (csvLyr.sourceFields)
+                    visible={csvLayer.visible}
+                    alpha={csvLayer.alpha}
+                    url={csvLayer.url}
+                    longitudefieldname={csvLayer.longitudeFieldName}
+                    latitudefieldname={csvLayer.latitudeFieldName}/>;
+
+            if (csvLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(csvLayer.refreshInterval);
+            }
+
+            if (!csvLayer.showInLegend)
+            {
+                layerXML.@showinlegend = false;
+            }
+
+            if (csvLayer.columnDelimiter != ",")
+            {
+                layerXML.@columndelimiter = csvLayer.columnDelimiter;
+            }
+
+            if (csvLayer.sourceFields)
             {
                 var fields:Array = [];
-                for each (var field:Field in csvLyr.sourceFields)
+                for each (var field:Field in csvLayer.sourceFields)
                 {
                     fields.push(field.name + "|" + field.alias + "|" + field.type);
                 }
-                lyrXML.@sourcefields = fields.join();
+                layerXML.@sourcefields = fields.join();
             }
         }
         else if (layer is FeatureLayer && !(layer is CSVLayer))
         {
-            var feaLyr:FeatureLayer = layer as FeatureLayer;
-            if (!feaLyr.featureCollection)
-            {
-                lyrXML = <layer label={label}
+            var feaLayer:FeatureLayer = layer as FeatureLayer;
+
+            if (!feaLayer.featureCollection)
+            {
+                layerXML = <layer label={label}
                         type="feature"
-                        visible={feaLyr.visible}
-                        alpha={feaLyr.alpha}
-                        mode={feaLyr.mode}
-                        url={feaLyr.url}
-                        iseditable={feaLyr.isEditable}
-                        useproxy={feaLyr.proxyURL != null}/>;
-                if (feaLyr.refreshInterval > 0)
-                {
-                    lyrXML.@autorefresh = minutesToSeconds(feaLyr.refreshInterval);
-                }
-                if (!feaLyr.showInLegend)
-                {
-                    lyrXML.@showinlegend = false;
+                        visible={feaLayer.visible}
+                        alpha={feaLayer.alpha}
+                        mode={feaLayer.mode}
+                        url={feaLayer.url}
+                        iseditable={feaLayer.isEditable}
+                        useproxy={feaLayer.proxyURL != null}/>;
+
+                if (feaLayer.refreshInterval > 0)
+                {
+                    layerXML.@autorefresh = minutesToSeconds(feaLayer.refreshInterval);
+                }
+
+                if (!feaLayer.showInLegend)
+                {
+                    layerXML.@showinlegend = false;
                 }
             }
         }
         else if (layer is GeoRSSLayer)
         {
             var geoRSSLayer:GeoRSSLayer = layer as GeoRSSLayer;
-            lyrXML = <layer label={label}
+
+            layerXML = <layer label={label}
                     type="georss"
                     visible={geoRSSLayer.visible}
                     alpha={geoRSSLayer.alpha}
                     url={geoRSSLayer.url}/>;
+
             if (geoRSSLayer.refreshInterval > 0)
             {
-                lyrXML.@autorefresh = minutesToSeconds(geoRSSLayer.refreshInterval);
-            }
+                layerXML.@autorefresh = minutesToSeconds(geoRSSLayer.refreshInterval);
+            }
+
             if (!geoRSSLayer.showInLegend)
             {
-                lyrXML.@showinlegend = false;
-            }
+                layerXML.@showinlegend = false;
+            }
+
             if (geoRSSLayer.serviceURL)
             {
-                lyrXML.@serviceurl = geoRSSLayer.serviceURL;
-            }
+                layerXML.@serviceurl = geoRSSLayer.serviceURL;
+            }
+
             if (geoRSSLayer.pointSymbol)
             {
-                lyrXML.appendChild(getPointSymbolXML(geoRSSLayer.pointSymbol));
-            }
+                layerXML.appendChild(getPointSymbolXML(geoRSSLayer.pointSymbol));
+            }
+
             if (geoRSSLayer.polylineSymbol)
             {
-                lyrXML.appendChild(getLineSymbolXML(geoRSSLayer.polylineSymbol));
-            }
+                layerXML.appendChild(getLineSymbolXML(geoRSSLayer.polylineSymbol));
+            }
+
             if (geoRSSLayer.polygonSymbol)
             {
-                lyrXML.appendChild(getPolygonSymbolXML(geoRSSLayer.polygonSymbol));
+                layerXML.appendChild(getPolygonSymbolXML(geoRSSLayer.polygonSymbol));
             }
         }
         else if (layer is KMLLayer)
         {
-            var kmlLyr:KMLLayer = layer as KMLLayer;
-            lyrXML = <layer label={label}
+            var kmlLayer:KMLLayer = layer as KMLLayer;
+
+            layerXML = <layer label={label}
                     type="kml"
-                    visible={kmlLyr.visible}
-                    alpha={kmlLyr.alpha}
-                    url={kmlLyr.url}/>;
-            if (kmlLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(kmlLyr.refreshInterval);
-            }
-            if (!kmlLyr.showInLegend)
-            {
-                lyrXML.@showinlegend = false;
+                    visible={kmlLayer.visible}
+                    alpha={kmlLayer.alpha}
+                    url={kmlLayer.url}/>;
+
+            if (kmlLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(kmlLayer.refreshInterval);
+            }
+
+            if (!kmlLayer.showInLegend)
+            {
+                layerXML.@showinlegend = false;
             }
         }
         else if (layer is OpenStreetMapLayer)
         {
-            var osmLyr:OpenStreetMapLayer = layer as OpenStreetMapLayer;
-            lyrXML = <layer label={label}
+            var osmLayer:OpenStreetMapLayer = layer as OpenStreetMapLayer;
+
+            layerXML = <layer label={label}
                     type="osm"
-                    visible={osmLyr.visible}
-                    alpha={osmLyr.alpha}/>;
-            if (osmLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(osmLyr.refreshInterval);
-            }
-            if (!osmLyr.showInLegend)
-            {
-                lyrXML.@showinlegend = false;
+                    visible={osmLayer.visible}
+                    alpha={osmLayer.alpha}/>;
+
+            if (osmLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(osmLayer.refreshInterval);
+            }
+
+            if (!osmLayer.showInLegend)
+            {
+                layerXML.@showinlegend = false;
             }
         }
         else if (layer is VETiledLayer)
         {
-            var veLyr:VETiledLayer = layer as VETiledLayer;
-            lyrXML = <layer label={label}
+            var veLayer:VETiledLayer = layer as VETiledLayer;
+
+            layerXML = <layer label={label}
                     type="bing"
-                    visible={veLyr.visible}
-                    alpha={veLyr.alpha}
-                    style={veLyr.mapStyle}/>;
-            if (veLyr.refreshInterval > 0)
-            {
-                lyrXML.@autorefresh = minutesToSeconds(veLyr.refreshInterval);
-            }
-            if (!veLyr.showInLegend)
-            {
-                lyrXML.@showinlegend = false;
-            }
-            if (veLyr.displayLevels)
-            {
-                lyrXML.@displaylevels = veLyr.displayLevels.join();
+                    visible={veLayer.visible}
+                    alpha={veLayer.alpha}
+                    style={veLayer.mapStyle}/>;
+
+            if (veLayer.refreshInterval > 0)
+            {
+                layerXML.@autorefresh = minutesToSeconds(veLayer.refreshInterval);
+            }
+
+            if (!veLayer.showInLegend)
+            {
+                layerXML.@showinlegend = false;
+            }
+
+            if (veLayer.displayLevels)
+            {
+                layerXML.@displaylevels = veLayer.displayLevels.join();
             }
         }
         else if (layer is WMSLayer)
         {
             var wmsLayer:WMSLayer = layer as WMSLayer;
-            lyrXML = <layer label={label}
+
+            layerXML = <layer label={label}
                     type="wms"
                     visible={wmsLayer.visible}
                     alpha={wmsLayer.alpha}

                    skipgetcapabilities={wmsLayer.skipGetCapabilities}
                    imageformat={wmsLayer.imageFormat}
                    url={wmsLayer.url}/>;
            if (wmsLayer.refreshInterval > 0)
            {
                lyrXML.@autorefresh = minutesToSeconds(wmsLayer.refreshInterval);
            }
            if (!wmsLayer.showInLegend)
            {
                lyrXML.@showinlegend = false;
            }
            if (wmsLayer.copyright)
            {
                lyrXML.@copyright = wmsLayer.copyright;
            }
            if (wmsLayer.spatialReference)
            {
                lyrXML.@wkid = wmsLayer.spatialReference.wkid;
            }
            if (wmsLayer.maxImageHeight > 0)
            {
                lyrXML.@maximageheight = wmsLayer.maxImageHeight;
            }
            if (wmsLayer.maxImageWidth > 0)
            {
                lyrXML.@maximagewidth = wmsLayer.maxImageWidth;
            }
            if (wmsLayer.visibleLayers)
            {
                lyrXML.@visiblelayers = wmsLayer.visibleLayers.toArray().join();
            }
        }
        else if (layer is WMTSLayer)
        {
            var wmtsLayer:WMTSLayer = layer as WMTSLayer;
            lyrXML = <layer label={label}
                    type="wmts"
                    visible={wmtsLayer.visible}
                    alpha={wmtsLayer.alpha}

            var hasSupportedTileInfo:Boolean = ObjectUtil.compare(defaultTileInfo, webTiledLayer.tileInfo) == 0;
            if (hasSupportedTileInfo)
            {
                layerXML = <layer label={label}
                        type="webtiled"
                        visible={webTiledLayer.visible}
                        alpha={webTiledLayer.alpha}
                        url={webTiledLayer.urlTemplate}/>;

                if (webTiledLayer.refreshInterval > 0)
                {
                    layerXML.@autorefresh = minutesToSeconds(webTiledLayer.refreshInterval);
                }

                if (!webTiledLayer.showInLegend)
                {
                    layerXML.@showinlegend = false;
                }

                if (webTiledLayer.copyright)
                {
                    layerXML.@copyright = webTiledLayer.copyright;
                }

                if (webTiledLayer.displayLevels)
                {
                    layerXML.@displaylevels = webTiledLayer.displayLevels.join();
                }

                if (webTiledLayer.subDomains)
                {
                    layerXML.@subdomains = webTiledLayer.subDomains.join();
                }
            }
        }

        return layerXML;
    }

    private static function minutesToSeconds(minutes:Number):Number
