Thursday, November 17, 2011

Easy XBRL Scripting with Gepsio and PowerShell

Microsoft’s PowerShell scripting environment provides full support for using .NET objects, which makes it an ideal scripting language for use with Gepsio. PowerShell and Gepsio can work together to make working with XBRL data very easy.

Here is a simple PowerShell script that pulls an XBRL document from the SEC site and displays some simple information about the document:

Add-Type -Path "C:\GepsioPath\JeffFerguson.Gepsio.dll"

$XbrlDoc = New-Object -TypeName JeffFerguson.Gepsio.XbrlDocument

$DocumentLocation = "http://www.sec.gov/Archives/edgar/data/21344/000104746911006790/ko-20110701.xml"
Write-Host "Loading and validating" $DocumentLocation"..."
$XbrlDoc.Load($DocumentLocation)

foreach($CurrentFragment in $XbrlDoc.XbrlFragments)
{
Write-Host $CurrentFragment.Facts.Count "facts in fragment."
Write-Host $CurrentFragment.Units.Count "units in fragment."
Write-Host $CurrentFragment.Contexts.Count "contexts in fragment."
}



This script gives the following output:

Loading and validating http://www.sec.gov/Archives/edgar/data/21344/000104746911006790/ko-20110701.xml...
1081 facts in fragment.
4 units in fragment.
281 contexts in fragment.



Let’s take a look at the script in more detail. It begins by adding the Gepsio runtime into the PowerShell environment with a call to the Add-Type command:

Add-Type -Path "C:\GepsioPath\JeffFerguson.Gepsio.dll"



Every PowerShell script that uses Gepsio will need to use this command so that the Gepsio runtime can be used by the PowerShell script.


Once Gepsio is loaded, a new Gepsio XbrlDocument object is created and saved in a variable:

$XbrlDoc = New-Object -TypeName JeffFerguson.Gepsio.XbrlDocument



This statement states that a new .NET object of type JeffFerguson.Gepsio.XbrlDocument, which is the Gepsio type that represents an XBRL document, should be created and be made available in a PowerShell script variable called $XbrlDoc.


One the new XbrlDocument object is created, another PowerShell variable is created to describe the address of the document to be loaded:

$DocumentLocation = "http://www.sec.gov/Archives/edgar/data/21344/000104746911006790/ko-20110701.xml"



This statement creates a new PowerShell script variable called $DocumentLocation and assigns it a string of “http://www.sec.gov/Archives/edgar/data/21344/000104746911006790/ko-20110701.xml”. This is the address of the XBRL document that the script should load.


Once the address of the XBRL document is made available, it is loaded into the Gepsio XbrlDocument object through a call to the XbrlDocument.Load() method:

$XbrlDoc.Load($DocumentLocation)



Gepsio treats an XbrlDocument as a collection of XbrlFragment objects. Each XBRL fragment is XML data having the <xbrl> tag as its root. Generally, an XBRL document will have only one XbrlFragment, although Gepsio supports documents that may have more than one fragment. The script iterates through each fragment in the document and examines the Xbrlfragment object’s three main collections: Facts, Units and Contexts. Each collection has a property called Count, and each of these counts are displayed as script output:

foreach($CurrentFragment in $XbrlDoc.XbrlFragments)
{
Write-Host $CurrentFragment.Facts.Count "facts in fragment."
Write-Host $CurrentFragment.Units.Count "units in fragment."
Write-Host $CurrentFragment.Contexts.Count "contexts in fragment."
}



Future blog posts will explore PowerShell’s access to the Gepsio runtime in more detail.

Monday, November 7, 2011

Gepsio Available as a NuGet Package

Beginning with the recently-released Nov 2011 CTP, Gepsio is now available via NuGet as well as from the project Web site. The name of the NuGet package is JeffFerguson.Gepsio, so, from within the Package Manager Console in Visual Studio 2010, you can execute the following command:

PM> Install-Package JeffFerguson.Gepsio

You will also find it from the “Manage NuGet Packages” submenu item from the “Library Package Manager” menu item on the Visual Studio 2010 “Tools” menu. Just search for Gepsio:

image

Tuesday, November 1, 2011

Nov 2011 CTP Released

I am pleased to announce the Nov 2011 CTP release of Gepsio. This release passes 191 of the tests in the XBRL-CONF-CR3-2007-03-05 conformance suite (which is 32 more than the 159 tests that passed in the last CTP release). This release builds on the previous CTP release in the following ways:

  • First Class Support For Items and Tuples. Previous releases of Gepsio used a single class called Fact to represent a fact in an XBRL fragment. Starting with this release, the Fact class is a base class for two derived classes: one called Item and the other called Tuple. The Facts collection available from an XbrlFragment object is a collection of Fact objects, and each Fact in the collection could, in fact, be either an Item object or a Tuple object. This work brings the XBRL concept of tuples in as a first-class citizen of the Gepsio object model.
  • Complete Support For Essence Aliases. This release of Gepsio passes all of the conformance suite tests relating to the concept of essence aliases.
  • Better Support For Calculation Arc Validation. Gepsio now has a better validation engine for calculation arcs. This release now includes better handling of context-equals and unit-equals items, items with a nil value, and better support for contributing concept items found in tuples.

Download this latest version (numbered 2.1.0.5) at http://gepsio.codeplex.com and click the “Downloads” tab to grab the latest release.