Skip to content

Find elements in a taxonomy

bseddon edited this page Nov 14, 2016 · 3 revisions

Elements in a taxonomy are accessed by calling the method $taxonomy->getElements() where $taxonomy is a variable that references an instance of the XBRL class or a descendant.

$elements = &$taxonomy->getElements();

The returned value is an array of elements defined in the schema document of the taxonomy. From here the the array can be queried to retrieve any type of element using standard PHP functions.

The index values used in the array is the id value of the element so this is the way to go if you know the id.

The elements of the array are the attributes you would expect to find in an tag in the schema:

Attribute Example
id uk-gaap_CostSales
name CostSales
type xbrli:monetaryItemType
substitutionGroup xbrli:item
periodType duration
balance debit
nillable true

An example of querying for all elements with a period type of 'duration' might be:

$duration = array_filter( $elements, function( $element ) {
                return isset( $element['periodType'] ) && $element['periodType'] == 'duration';
            } );

###Using the correct namespace

The $taxonomy variable value will have been set by a call to XBRL::loadTaxonomy or querying the the taxonomy of a loaded instance. However, the $taxonomy returned will be the main taxonomy of the DTS so may not be the one you want and not the one with schema file which defines the element.

It will usually be useful to make sure you are working with the correct taxonomy by explicitly retrieve the taxonomy for a namespace. This can be done using the getTaxonomyForNamespace the XBRL class:

$element_taxonomy = $taxonomy->getTaxonomyForNamespace( 'a valid namespace' );
Clone this wiki locally