Using GetMetadata to Get the Properties of a Specified Metadata Object |
If you have a set of objects for which you want to get common properties, you can use the GetMetadata method and set the OMI_INCLUDE_SUBTYPES (16) and OMI_TEMPLATE (4) flags.
In the request:
Specify the metadata type and Id= values of the objects for which you want to get properties in the <METADATA> element.
Specify additional properties that you want to get in one or more templates in a <TEMPLATES> element within the <OPTIONS> element. The templates that you specify must reference a metadata type that either matches or is a supertype of the metadata types specified in the <METADATA> element, as defined in the SAS Metadata Model.
The OMI_TEMPLATE flag instructs the GetMetadata method to get the properties specified in the templates for the objects specified in the <METADATA> element. The OMI_INCLUDE_SUBTYPES flag applies the templates to objects that are subtypes of the metadata types specified in the templates.
The following is an example of a GetMetadata method call that requests common properties from multiple objects. It is simple because it specifies one template:
<GetMetadata> <Metadata> <PhysicalTable Id="A58SW16P.B1000001"/> <Person Id="A58SW16P.AP0001JL"/> <Event Id="A58SW16P.B3000001"/> <WorkTable Id="A58SW16P.B4000001"/> <Document Id="A58SW16P.AY0000RT"/> </Metadata> <NS>SAS</NS> <!-- OMI_TEMPLATE + OMI_INCLUDE_SUBTYPES --> <Flags>20</Flags> <Options> <Templates> <Root Name="" Desc="" UsageVersion=""> <Extensions/> </Root> </Templates> </Options> </GetMetadata>
In the method call, note the following:
The <METADATA> element specifies five metadata objects from which to get properties.
The <NS> element specifies the namespace.
The <FLAGS> element specifies the OMI_TEMPLATE and OMI_INCLUDE_SUBTYPES (4 +16 = 20) flags.
The <OPTIONS> element includes a <TEMPLATES> element and specifies a template that instructs the method to get attributes and associations for the Root metadata type. The Root metadata type is the supertype of all of the metadata types defined in the SAS Metadata Model. Therefore, the properties requested for the Root object are returned for all of the objects specified in the <METADATA> element.
The following is an example of the output returned by the SAS Metadata Server:
<Metadata> <PhysicalTable Id="A58SW16P.B1000001" Name="Patient Information" Desc="Information describing an individual patient." UsageVersion="0"> <Extensions/> </PhysicalTable> <Person Id="A58SW16P.AP0001JL" Name="Created Person 1" Desc="Person created for GetMetadata" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JL" Name="Attrib 1" Desc="First attribute" UsageVersion="0"><Extensions/></Extension> <Extension Id="A58SW16P.AC0001JM" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"><Extensions/></Extension> </Extensions> </Person> <Event Id="A58SW16P.B3000001" Name="Event 1 for GetMetadata" Desc="Event added" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JN" Name="Attrib 1" Desc="First attribute" UsageVersion="0"><Extensions/></Extension> <Extension Id="A58SW16P.AC0001JO" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"><Extensions/></Extension> </Extensions> </Event> <WorkTable Id="A58SW16P.B4000001" Name="WorkTable 1 for getmet" Desc="WorkTable added" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JP" Name="Attrib 1" Desc="First attribute" UsageVersion="0"><Extensions/></Extension> <Extension Id="A58SW16P.AC0001JQ" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"><Extensions/></Extension> </Extensions> </WorkTable> <Document Id="A58SW16P.AY0000RT" Name="Document 1 for getmet" Desc="doc added" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JR" Name="Attrib 1" Desc="First attribute" UsageVersion="0"><Extensions/></Extension> <Extension Id="A58SW16P.AC0001JS" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"><Extensions/></Extension> </Extensions> </Document> </Metadata>
In the output, note the following:
The GetMetadata method returned the Name=, Desc=, and UsageVersion= attribute values for all of the objects specified in the <METADATA> element.
The PhysicalTable object had no Extension objects associated with it through the Extensions association. The Person, Event, WorkTable, and Document objects each had two Extension objects defined through the Extensions association.
The method attempted to list Extension objects that were associated to the Extension objects (because Extension is a subtype of Root), but none were found.
The values of Name=, Desc=, and UsageVersion= attributes were also returned for the Extension objects (because Extension is a subtype of Root).
The following is an example of a GetMetadata method call that sets the OMI_INCLUDE_SUBTYPES flag and specifies multiple templates in the <TEMPLATES> element. When you specify more than one template in the <TEMPLATES> element, the order in which the templates are specified is important. The templates are applied in the order specified. If two or more templates apply to the same metadata type, the first template found is applied. The other templates are ignored. For example:
<GetMetadata> <Metadata> <PhysicalTable Id="A58SW16P.B1000001"/> <Person Id="A58SW16P.AP0001JL"/> <Event Id="A58SW16P.B3000001"/> <WorkTable Id="A58SW16P.B4000001"/> <Document Id="A58SW16P.AY0000RT"/> </Metadata> <NS>SAS</NS> <!-- OMI_TEMPLATE + OMI_INCLUDE_SUBTYPES --> <Flags>20</Flags> <Options> <Templates> <DataTable Name="" UsageVersion=""> <Documents/> <Columns/> </DataTable> <Root Name="" Desc="" UsageVersion=""> <Extensions/> </Root> <Document Name="" Desc=""/> </Templates> </Options> </GetMetadata
This method call specifies three templates in the <TEMPLATES> element. One template is for the DataTable metadata type. One template is for the Root metadata type. And, one template is for the Document metadata type. Because OMI_INCLUDE_SUBTYPES is set, the GetMetadata method processes the templates as follows:
DataTable is the supertype of the PhysicalTable and WorkTable metadata types. Therefore, the method returns the requested Name= and UsageVersion= attributes for all of these objects, and any objects associated to them through the Documents and Columns associations.
Because the first template did not specify what properties to get for any associated Document and Column objects, the method consults the second template. Because the Root metadata type is the supertype of all metadata types, the properties requested for the Root object are retrieved for the Document and Column objects that were retrieved by the first template. The properties are also retrieved for the remaining objects identified in the <METADATA> element.
Because the third template specifies a metadata object that has already been processed by the second template, it is ignored.
The following is an example of the output returned by the SAS Metadata Server:
<Metadata> <PhysicalTable Id="A58SW16P.B1000001" Name="Patient Information" UsageVersion="0"> <Documents/> <Columns> <Column Id="A58SW16P.B2000001" Name="Patient ID" Desc="Patient Information" UsageVersion="0"><Extensions/></Column><Column Id="A58SW16P.B2000002" Name="Initials" Desc="Patient Initials" UsageVersion="0"> <Extensions/> </Column> <Column Id="A58SW16P.B2000003" Name="Sex" Desc="Sex of Patient" UsageVersion="0"><Extensions/></Column> <Column Id="A58SW16P.B2000004" Name="Date Of Birth" Desc="Date Of Birth" UsageVersion="0"> <Extensions/> </Column> <Column Id="A58SW16P.B2000005" Name="Sponsor Patient ID" Desc="Sponsor Patient Information" UsageVersion="0"> <Extensions/> </Column> <Column Id="A58SW16P.B2000006" Name="Weight In Pounds" Desc="Patient Weight In Pounds" UsageVersion="0"> <Extensions/> </Column> <Column Id="A58SW16P.B2000007" Name="Weight In Kilograms" Desc="Patient Weight In Kilograms" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0000RU" Name="Algorithm" Desc="Algorithm for column." UsageVersion="0"> <Extensions/> </Extension> </Extensions> </Column> </Columns> </PhysicalTable> <Person Id="A58SW16P.AP0001JL" Name="Created Person 1 for getmet" Desc="getmet07" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JL" Name="Attrib 1" Desc="First attribute" UsageVersion="0"> <Extensions/> </Extension> <Extension Id="A58SW16P.AC0001JM" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"> <Extensions/> </Extension> </Extensions> </Person> <Event Id="A58SW16P.B3000001" Name="Event 1 for getmet" Desc="Event added" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JN" Name="Attrib 1" Desc="First attribute" UsageVersion="0"> <Extensions/> </Extension> <Extension Id="A58SW16P.AC0001JO" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"> <Extensions/> </Extension> </Extensions> </Event> <WorkTable Id="A58SW16P.B4000001" Name="WorkTable 1 for getmet" UsageVersion="0"> <Documents/> <Columns/> </WorkTable> <Document Id="A58SW16P.AY0000RT" Name="Document 1 for getmet" Desc="doc added" UsageVersion="0"> <Extensions> <Extension Id="A58SW16P.AC0001JR" Name="Attrib 1" Desc="First attribute" UsageVersion="0"> <Extensions/> </Extension> <Extension Id="A58SW16P.AC0001JS" Name="Attrib 2" Desc="Second attribute" UsageVersion="0"> <Extensions/> </Extension> </Extensions> </Document> </Metadata> <Ns>SAS</Ns> <Flags>20</Flags> <Options> <Templates> <DataTable Name="" usageVersion=""><Documents/><Columns/></DataTable> <Root Name="" Desc="" usageVersion=""><Extensions/></Root> <Document Name="" Desc=""/> </Templates> </Options> </GetMetadata>
In the output, the PhysicalTable object has no associated Document objects and has seven associated Column objects. One of the Column objects has an Extension object defined for it. The WorkTable object has no associated Document or Column objects. The method returned the properties requested for the Root metadata type for all remaining objects. If the OMI_INCLUDE_SUBTYPES flag had not been set in the method call, the results would have been different. In that case, the templates would have been applied in the order given, but the templates that specify the DataTable and Root metadata types would have been ignored.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.