03: GETTING FIELD NAMES

CONTENTdm uses nicknames for the metadata held in its records. The nicknames may or may not correspond to the actual field name. For instance, the title field might have a nickname of title, but Subject – LCSH might be called subjeca. Translating the field names is a job for dmGetCollectionFieldInfo.

API: dmGetCollectionFieldInfo

INVOKED: <server address>/dmwebservices/index.php?q=dmGetCollectionFieldInfo/<collection alias>/xml

EXAMPLE: https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCollectionFieldInfo/linl/xml

This will find the nicknames and proper field names for the Springfield Aviation Collection.

dmCollectionFieldInfo.php

 

<?php

// This function from Jacob Trunecek (http://stackoverflow.com/users/819364/jakub-trune%C4%8Dek)

function searchForId($id, $array) {
   foreach ($array as $key => $val) {
       if ($val['nick'] === $id) {
           return $key;
       }
   }
   return null;
}

$xmlData = file_get_contents('https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCollectionFieldInfo/linl/xml');

// Create the document object

$xml = simplexml_load_string($xmlData);

$result = array();

// Get the nodes and loop them

foreach ($xml->xpath('//field') as $record) {
        $result[] = array(
                'nick' => (string) $record->nick,
                'name' => (string) $record->name
        );
}

// Find the nickname of a term, find its array index, and then find the name value at the same index

$id = searchForId('dmoclcno', $result);
$name = $result[$id]["name"];

echo "Name: $name\n";




?>