ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / SetXml Method
Example

In This Topic
    SetXml Method (Project)
    In This Topic
    Sets the item’s metadata to the XML document provided as a string. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetXml( 
       string xml
    )
    Public Sub SetXml( _
       ByVal xml As String _
    ) 

    Parameters

    xml

    Return Value

    void
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    The metadata for this item cannot be edited
    Remarks
    Existing metadata is replaced. Metadata is created for the item if it doesn't already exist.
    Example
    Item: Set the metadata of an item: SetXML
    await QueuedTask.Run(() =>
    {
      var xml = System.IO.File.ReadAllText(@"E:\Data\Metadata\MetadataForFeatClass.xml");
      //Will throw InvalidOperationException if the metadata cannot be changed
      //so check "CanEdit" first
      if (featureClassMetadataItem.CanEdit())
        featureClassMetadataItem.SetXml(xml);
    });
    
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also