XQuery over XBRL documents

Aiming to implement a OLAP system over XBRL native document, some XML queries (XQuery) were important which I want to shared in this post.

This following queries can be interesting when the developer wish to get some data, which are within XBRL taxonomy (I mean, XBRL native documents).

1. Catching all elements of a XBRL Schema (XSD file):

declare namespace xsd=’http://www.w3.org/2001/XMLSchema’;
{for $e in doc(“db/xbrl/FILE_NAME.xsd”)//xsd:element
where $e/@substitutionGroup=”xbrli:item”   ( order by $e/@name   ( return {$e/@name}
}

2. Verifying if there is a specific element in the XBRL Schema (XSD file):

declare namespace xsd=’http://www.w3.org/2001/XMLSchema’;
distinct-values(doc(‘db/xbrl/FILE_NAME.xsd’)//xsd:element[contains(@name,’YouMustDescribeTheElementHere’)])

3. Querying specific XBRL element in XBRL instance (XML file) (e.g. according to specific context):

declare namespace us-gaap=’http://fasb.org/us-gaap/’;
distinct-values(doc(“db/xbrl/FILE_NAME.xml”)//us-gaap:AccountsPayableCurrent[contains(@contextRef, “YouMustDescribeHereTheContext”)])

* For tests I’ve utilized the Exist DBMS (http://www.exist-db.org/), which is native XML DBMS, free and open source, based on Java.

exist

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.