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.