# Enumerating keywords

An application can discover the set of keywords in a database record. By querying the type and certain qualifiers of each keyword, the application can obtain sufficient information to further process the keyword. If a keyword represents a data structure (such as a struct or array), the application can determine the elements within the data structure. By executing this process recursively, all values of all keywords of a managed object can be discovered. This process is called keyword enumeration.

This topic describes:

- Enumerating the top-level keywords

- Enumerating array keywords

- Enumerating struct keywords

- Enumerating StructAndArray keywords

The oaminfo demonstration program included with NMS OAM illustrates the keyword enumeration process. See Demonstration program for more information about oaminfo.

## Enumerating the top-level keywords

To enumerate the keywords for a managed object, first retrieve the top-level keywords. Then explore each keyword to determine the subkeywords it contains. Then explore those subkeywords, and so on.

All top-level keywords for a managed object are contained within a single struct with no name. To retrieve the top-level keywords for a managed object:

1. Get the number of elements in the no-name struct. To do so, invoke oamGetQualifier, specifying "" as the keyword, and Keywords.Count as the attribute to retrieve. oamGetQualifier returns the number of elements in the struct.

2. To determine the names of each of the elements within the struct, invoke oamGetQualifier repeatedly, each time specifying "" as the keyword, and Keywords[x] as the attribute to retrieve. oamGetQualifier returns a single element with each invocation.

## Enumerating array keywords

To determine how many items are contained in an array, use oamGetKeyword to get the value of keyword keyword.Count. For example, to determine how many items are in array DSPfile, invoke oamGetKeyword as follows:

oamGetKeyword( hObj, "DSPfile.Count", info, sizeof(info) );
sscanf( info, "%d",numElements )

You can then get each specific value x by invoking oamGetKeyword on keyword[x]:

oamGetKeyword( hObj, "DSPfile[1]", info, sizeof(info) );

If the returned value is a keyword, you can determine its Type attribute and perform further analysis and processing of the keyword.

## Enumerating struct keywords

To determine how many elements are contained within a struct, invoke oamGetQualifier on the Keywords.Count qualifier for the Struct keyword. For example, to get the number of keywords in struct Driver, use oamGetQualifier as follows:

oamGetQualifier( hObj, "Driver", "Keywords.Count", info, sizeof(info) );
sscanf( info, "%d",numElements )

To then determine the names of each of the elements within the struct, use the qualifier Keywords[x]. For example:

for ( i = 0; i < numFields; i++ )
{
char field[ 100 ];
sprintf( field, "Keywords[%d]", i );
oamGetQualifier(( ...., "Driver", field, .... );
}

The attribute string returned is in the form: keyword.keyword (for example, "Driver.Name"). By subsequently determining the Type attribute of the returned keyword name, you can perform further analysis and processing of the contents of the struct.

## Enumerating StructAndArray keywords

To perform keyword enumeration for a StructAndArray keyword, perform keyword enumeration treating it as an Array keyword (as described in Array keywords). This process enumerates the elements in the array represented by the keyword. Perform keyword enumeration treating it as a Struct keyword to enumerate the elements in the struct the keyword represents. By subsequently determining the Type attributes of each returned keyword name, you can perform further analysis and processing of the contents of the structs or arrays.