Creating a Template for DeleteMetadata

Purpose

User-defined templates are supported in DeleteMetadata to enable clients to delete custom logical metadata definitions. A custom logical metadata definition is a logical metadata definition that meets the following criteria:
  • does not use a PrimaryType subtype as its primary object
  • uses a PrimaryType subtype as its primary object, but does not store a value in the PublicType attribute
  • uses a PrimaryType subtype and specifies a PublicType value, but you want to delete a subset of its associations or associated objects
To delete a custom logical metadata definition:
  1. Specify the primary or top-level object in the logical metadata definition in the INMETADATA parameter.
  2. Specify the SAS namespace in the NS parameter.
  3. Set the OMI_TEMPLATE (4) flag in the FLAGS parameter.
  4. Specify a template in the <TEMPLATES> element in the OPTIONS parameter. The template should specify the association names to traverse to delete associated objects.
When the OMI_TEMPLATE (4) flag is set, and an appropriate user-defined template is submitted in the OPTIONS parameter, DeleteMetadata ignores the value in the metadata object's PublicType attribute if one is found, and deletes the specified associations instead.

Form of a DeleteMetadata Template

A DeleteMetadata template is a metadata property string that specifies the associations that should be deleted with the object instance that is specified in the INMETADATA parameter of the DeleteMetadata method. You can submit the metadata property string to the metadata server in two ways. Specify the metadata property string directly within the <TEMPLATES> element in the OPTIONS parameter, as follows:
<Templates>
    <MetadataType>
     <AssociationName1/>
     <AssociationName2/>
     <AssociationName3/>
   </MetadataType>
</Templates>
MetadataType is the same metadata type as in the INMETADATA parameter, and AssociationNamen are association names that are valid for MetadataType, as defined in the SAS Metadata Model.
Or, specify the metadata property string in a <TEMPLATE> subelement in the <TEMPLATES> element in the OPTIONS parameter, as follows:
<Templates>
 <Template TemplateName="name">
   <MetadataType>
     <AssociationName1/>
     <AssociationName2/>
     <AssociationName3/>
   </MetadataType>
  </Template>
</Templates>
When the second way is used, the INMETADATA property string must specify a TemplateName attribute with a matching value.
The new template form is useful when you are deleting multiple entities at once. It is also useful when you want to take advantage of the new template attributes in SAS 9.3. For more information, see Template Attributes. Also, see Examples. Otherwise, the legacy template form is more efficient and sufficient for most requests.

How DeleteMetadata Processes a User-Defined Template

The DeleteMetadata method processes requests that contain a template as follows:
  • The OMI_TEMPLATE flag instructs the DeleteMetadata method to look for a user-defined template in a <TEMPLATES> subelement in the OPTIONS parameter.
    • If a TemplateName attribute is specified in the INMETADATA parameter, the server looks for a <TEMPLATE> subelement that has a matching TemplateName value in the OPTIONS parameter and uses it if it is found. If a matching named template is not found in the OPTIONS parameter, the server returns an error.
    • If a TemplateName attribute is not specified in the INMETADATA parameter, the server looks for a metadata property string of the same metadata type that was specified in the INMETADATA parameter in the <TEMPLATES> element in the OPTIONS parameter and uses it if it is found. If a matching metadata type is not found, and the object is a PrimaryType subtype with a valid value in the PublicType attribute, then the SAS type dictionary is used to delete the object. Otherwise, the server deletes the specified object only.

Examples

The following example shows how to issue a DeleteMetadata request that submits a user-defined template using the legacy template form. The specified Group has four objects associated through the Members association: a PhysicalTable object named “My Table,” a PhysicalTable object named “Their Table,” a TextStore object named “My Notes,” and a TextStore object named “Their Notes.” The request specifies to delete the Group object and all objects associated to it through the Members association. The request is formatted for the INMETADATA parameter of the DoRequest method:
<DeleteMetadata>
<Metadata>
<Group Id="A5TJRDIT.A1000004" Name="My Group"/>
</Metadata>
<Ns>SAS</Ns>
<!-- OMI_TRUSTED_CLIENT, OMI_TEMPLATE, + OMI_RETURN_LIST -->
<Flags>268436484</Flags>
<Options>
<Templates>
 <Group>
   <Members/>
</Group>
</Templates>
</Options>
</DeleteMetadata>
Here is sample output from the request, reformatted for readability:
<DeleteMetadata>
<Metadata>
<Group Id="A5TJRDIT.A1000004"/>
<PhysicalTable Id="A5TJRDIT.B20000TF"/>
<PhysicalTable Id="A5TJRDIT.B20000TG"/>
<TextStore Id="A5TJRDIT.AE0001D9"/>
<TextStore Id="A5TJRDIT.AE0001DA"/>
</Metadata>
<Ns>SAS</Ns>
<Flags>268436484</Flags>
<Options>
<Templates>
<Group>
<Members/>
</Group>
</Templates>
</Options>
</DeleteMetadata>
The following example shows how to issue a DeleteMetadata request that submits a user-defined template using the new template form. This request specifies to delete the Group object described in the previous example. However, in this request, we specify to delete the Group object, and its associated My Table and My Notes objects, leaving the other two objects intact.
<DeleteMetadata>
 <Metadata>
 <Group Id="A5TJRDIT.A1000004" TemplateName="test"/>
 </Metadata>
<Ns>SAS</Ns>
<!-- OMI_TRUSTED_CLIENT, OMI_TEMPLATE, + OMI_RETURN_LIST -->
<Flags>268436484</Flags>
<Options>
<Templates>
<Template TemplateName="test">
<Group>
 <Members>
   <PhysicalTable match="@Name='My Table'" TemplateExpand="Yes"/>
   <PhysicalTable TemplateExpand="No"/>
   <TextStore match="@Name='My Notes'" TemplateExpand="Yes"/>
   <TextStore TemplateExpand="No"/>
  </Members>
 </Group>
</Template>
</Templates>
</Options>
</DeleteMetadata>
Here is sample output from the request, reformatted for readability:
<DeleteMetadata>
<Metadata>
<Group Id="A5TJRDIT.A1000004"/>
<PhysicalTable Id="A5TJRDIT.B20000TF"/>
<TextStore Id="A5TJRDIT.AE0001D9"/>
</Metadata>
<Ns>SAS</Ns>
<Flags>268436484</Flags>
<Options>
<Templates>
<Template TemplateName="test">
<Group>
<Members>
<PhysicalTable match="@Name='My Table'" TemplateExpand="Yes"/>
<PhysicalTable TemplateExpand="No"/>
<TextStore match="@Name='My Notes'" TemplateExpand="Yes"/>
<TextStore TemplateExpand="No"/>
</Members>
</Group>
</Template>
</Templates>
</Options>
</DeleteMetadata>
The Match and TemplateExpand attributes are used to filter the associated objects that are deleted. TextStore and PhysicalTable objects that do not meet the match criteria are ignored.