XBRLInstance

From XBRLWiki
Jump to navigationJump to search

[XBRLInstance javadoc page]

Description

An XBRLInstance object represents the content of an XBRL Report. This is:

  • all XBRL facts , and
  • all XBRL contexts, and
  • all XBRL units, and
  • all Footnote Linkbases, and
  • all references to XBRLTaxonomies, XBRLLinkbases, XBRLRoleRef and XBRLArcroleRef required for obtaining the DTS.

How to create an instance of an XBRLInstance object

There are several ways depending on what you are doing:

  • If the user have just created a new empty DTSContainer object and the purpose is to read the content of an XBRL report (and the whole referenced DTS) then the simplest way is to use one of the load methods in the DTSContainer object passing the document URI of the XBRL report. The returned object is an XBRLDocument that can be casted to an XBRLInstance.
  • If the user has already loaded a DTS (from a taxonomy file) and the purpose is to create a new XBRLInstance (in order to populate it with facts) then the user can use any of the available constructors. The most commonly used constructor is XBRLInstance(com.ihr.xbrl.om.DTSContainer) that accepts the current DTSContainer as a parameter and allows the user to start adding facts programatically.

Examples

Creation of a XBRLInstance object from a URL

/**
 * Sample, a new instance document is read form the file received as a parameter
 * After the instance object is obtained, the user can start working with it
 */
public class SampleReadInstance {

	public static void main(String[] args) throws Exception {
		DTSContainer dts = DTSContainer.newEmptyContainer();
		XBRLInstance instance = (XBRLInstance)dts.load(new File(args[0]).toURI());
		// ... rest of the application code goes here
	}
}

Creation of a new instance docyment for a DTS after the DTS has been loaded

/**
 * Sample, a new instance document is created after the DTS has been loaded
 */
public class SampleCreateInstanceForDTS {

	public static void main(String[] args) throws Exception {
		DTSContainer dts = DTSContainer.newEmptyContainer();
		dts.load(new File("sampleTaxonomy.xsd").toURI());
		XBRLInstance instance = new XBRLInstance(dts);
		// ... rest of the application code goes here
	}
}

Working with facts in an XBRLInstance

This section describes two abstract operations that the user can execute on XBRLInstance objects regardless the way they have been created.

The XBRLInstance object is able to automatically change in order to keep consistency during operations. For example, the action of adding a new XBRLFact item to the XBRLInstance may automatically add a new context or may reuse an existing context instead. The same happens with the unit and with the reference to the required taxonomy schema. Removing facts from the XBRLInstance is also an operation that keeps the instance document content consistent while silently removes content that is no longer used (like unused units or contexts etc).

Read access

Read access is an abstract operation implemented in several methods that allows the user to access to the content of the XBRLInstance. The content of an XBRLInstance can be accessed in two modes: sequential mode and indexed mode. Both modes are described in the XBRLFactsList interface.

Write access

Modifying the content of the XBRLInstance is normally implemented automatically inside the API at the time the user do operations that requires the API to keep the XBRLInstance consistent; for example, the action of creating a new fact automatically performs the operation of adding the new fact to the instance document. The user does not need to worry about how to keep consistency in the content of the XBRLInstance object.

Facts that the user can create with the API are:

Examples

In this example, the content of the XBRLInstance document is sequentially read in document order

	Iterator<XBRLFact> iterF = instance.iterator();
	while (iterF.hasNext()) {
		XBRLFact f = iterF.next();
		// ... do dome work with the fact
	}

In this example, a new XBRLNumericFact is added to the XBRLInstance

	// create the Non Numeric (Text) fact item
	XBRLFactNonNumeric fA = new XBRLFactNonNumeric(instance,ctx,itemA);
	// fA is nil until a value is assigned
	fA.setValue(new StringValue("test"));

Other operations

Creating a footnote for a fact

Creating a footnote requires some initial work on the XBRLInstance:

Create the footnotes container

A footnotes container is an extended link XLink container for footnotes. In order to create one, the user must first obtain or create the base for extended links for a particular type and role. The next call is for creating the footnote link container itself.

Here is an example about how to create the base and then one extended link for footnotes

	// Create a DTSBase for footnote extended links 
        // The standard role is http://www.xbrl.org/2003/role/link
	DTSBase base = dts.getBase(
		FootnoteLinkbase.lbType, 
		dts.getStaticRoleTypeByURI(XBRLExtendedLink.standard_role_URI));

	// Now create a container for footnotes (Footnote Extended Link)
	FootnoteLinkbase fl = new FootnoteLinkbase(instance, base);
Create the fact
Create the footnote resource
Create the relationship linking the fact with the footnote

Navigation

Main Page | XBRL API related discussions