ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / Geometry Class / ToXml Method
Example

In This Topic
    ToXml Method (Geometry)
    In This Topic
    Serializes this geometry instance into an ArcGIS XML geometry representation.
    Syntax
    public string ToXml()
    Public Function ToXml() As String

    Return Value

    Geometry represented as an XML string.
    Example
    Construct GeometryBag - from JSON, Xml
    const string jsonString = "{\"geometries\":[{\"x\":1,\"y\":2},{\"rings\":[[[0,0],[0,4],[3,4],[3,0],[0,0]]]}],\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}";
    //At 2.x - GeometryBag geometryBag = GeometryBagBuilder.FromJson(jsonString);
    var geometryBag = GeometryBagBuilderEx.FromJson(jsonString);
    
    string xml = geometryBag.ToXml();
    //At 2.x - GeometryBag xmlString = GeometryBagBuilder.FromXML(xml);
    var xmlString = GeometryBagBuilderEx.FromXml(xml);
    
    Import and Export Geometries to XML
    MapPoint minPoint = MapPointBuilderEx.CreateMapPoint(1, 1, 1, 1, 3);
    MapPoint maxPoint = MapPointBuilderEx.CreateMapPoint(5, 5, 5);
    
    // 
    //  MapPoint
    // 
    string xml = minPoint.ToXml();
    MapPoint minPointImport = MapPointBuilderEx.FromXml(xml);
    // minPointImport = minPoint
    
    //
    // Envelope
    //
    Envelope envelopeWithID = EnvelopeBuilderEx.CreateEnvelope(minPoint, maxPoint);
    
    // Envelopes don't have IDs
    // envelopeWithID.HasID = false
    // envelopeWithID.HasM = true
    // envelopeWithID.HasZ = true
    
    xml = envelopeWithID.ToXml();
    Envelope envelopeImport = EnvelopeBuilderEx.FromXml(xml);
    
    //
    // Multipoint
    //
    List<MapPoint> list = new List<MapPoint>();
    list.Add(minPoint);
    list.Add(maxPoint);
    
    Multipoint multiPoint = MultipointBuilderEx.CreateMultipoint(list);
    
    xml = multiPoint.ToXml();
    Multipoint multipointImport = MultipointBuilderEx.FromXml(xml);
    // multipointImport.PointCount == 2
    // multipointImport.HasID = true
    // multipointImport.HasM = true
    // multipointImport.HasZ= true
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also