Sunday, September 9, 2012

Sep 2012 CTP Released

The Sep 2012 CTP release of Gepsio is now available! Download the latest binary from the project’s Download page.

Here’s a peek at the newest enhancements to the latest build of Gepsio:

Role Types

Role types found in schemas are now available from within Gepsio. The XbrlSchema class now contains a property called RoleTypes. This property is a collection of objects of a new class called RoleType. Objects of the RoleType class expose any role types defined in the schema.

HTTP-Based Schema Linkbase References

Gepsio now supports HTTP-based schema linkbase references. Previous releases assumed that all schema linkbase references were based on local filesystem paths.

CalculationLink.Linkbase Property

The CalculationLink class contains a new property called Linkbase, which references the LinkbaseDocument object containing the calculation link.

LinkbaseDocument.Schema Property

The LinkbaseDocument class contains a new property called Schema, which references the XbrlSchema class referencing the linkbase document.

SummationConcept.Link Property

The SummationConcept class contains a new property called Link, which references the CalculationLink object containing the summation concept.

Resolved Issues

Work Item 9401: Valid XBRL Doc Failing To Be Loaded

The latest Amazon quarterly XBRL filing passes other validation tests I used, however attempting to Load the doc in Gepsio throws an error. Since it is an Object Ref Not Set to Instance error, it is not entirely clear what caused it although the final line in the stack trace is JeffFerguson.Gepsio.QualifiedName.Equals(Object obj). I attach the filing for your ref. Any ideas on how to get around this?

A bug in the QualifiedName equality testing code failed to detect various null conditions. This has been fixed.

Work Item 7843: The given path's format is not supported

Fixed bug that allowed paths of the form "file:///C:/blah/blah/http://blah/blah.org" to be created in GetFullLinkbasePath when filings that reference remote documents are stored locally. This caused a NotSupportedException to be thrown. Supplied as a patch from Codeplex user matthewschrager.

 

Work Item 9465: WebException Objects Thrown During XbrlSchema Creation Are Not Wrapped in XbrlException Objects

The XbrlSchema constructor uses an XmlTextReader to read an XBRL schema. If the URI for the XBRL schema to be read is an HTTP-based URI, then the XmlTextReader will use the .NET Web stack to read the schema using HTTP. If something fails during that process, the .NET Web stack will throw a WebException. Thrown WebException objects were not wrapped in an XbrlException object and were consequently thrown back to the client as a WebException object.

To be clear that the issue is an XBRL issue caused by an HTTP failure, the XBRL schema creation code now creates an XbrlException object, stores the caught WebException as an inner exception to the XbrlException, and throws the XbrlException object back up to the client.

Work Item 9571: No Support for Taxonomy Role Types

Role types found in schemas are now available from within the object model. The XbrlSchema class now contains a property called RoleTypes. This property is a collection of objects of a new class called RoleType. Objects of the RoleType class expose any role types defined in the schema.

Thursday, September 6, 2012

Gepsio on Twitter

I’ve just opened a Twitter account for Gepsio announcements, so I can keep them separate from my main (unfocused) Twitter account. I’m planning on using Gepsio’s Twitter account in much the same way as I use Gepsio’s Facebook page (www.facebook.com/gepsio) in that I will be announcing blog postings, release notes, bug fixes, and answering your questions.
Follow Gepsio on Twitter at @GepsioXbrl … see you there!

Monday, September 3, 2012

Gepsio XBRL Validation Strategies: The Present and the Future

I’ve just received the following email:

I’ve had a chance by now to examine a fair number  of SEC Xbrl documents using Gepsio with my [code].  I’m consistently seeing around 9-10 % of the documents in a given processing session that fail to load …

In my project … I am processing a fixed number specific data points.

I only need a few data points with their durations, start and end dates, along with basic entity information and fiscal period focus info.   But I need this for a large number of documents.

I am wondering if the careful and thorough validation done on document.Load, which is really necessary for many users of Gepsio, might be overkill for what I am doing.  

Could some of this validation be preventing the load of documents that might be flawed in ways that would leave them still usable for my project?

I don’t know much about xml or xbrl but I get the sense that some of the validation occurring is relevant mainly to the re- presentation of the data, not so much putting the data into a db.

Does it make any sense to think about an optional overloaded version of the document.load method with parameters that could cause it to skip some validation of things that might be peripheral to processes like mine?

This is a very thought provoking approach, as it echoes a thought that I have had for some time. Let me begin by explaining Gepsio’s current approach to reporting on XBRL validation issues and follow that up with a possible design change.

Gepsio’s Current XBRL Validation Strategy

Today, Gepsio validates a loaded document against the XBRL specification after the document is loaded. An exception is thrown when the first XBRL specification violation is discovered. At a high level, the algorithm is as follows:

  1. load document as XML document
  2. if XML is invalid throw XML exception
  3. read taxonomy schema references
  4. read contexts
  5. read units
  6. read facts
  7. read footnote links
  8. validate context references
  9. if validation violation found throw XBRL exception
  10. validate unit references
  11. if validation violation found throw XBRL exception
  12. validate context time spans against period types
  13. if validation violation found throw XBRL exception
  14. validate footnote locations
  15. if validation violation found throw XBRL exception
  16. validate footnote arcs
  17. if validation violation found throw XBRL exception
  18. validate items
  19. if validation violation found throw XBRL exception

Today’s pattern asks callers to write code like this:

var myDoc = new XbrlDocument();
try
{
myDoc.Load("MyXbrlDocument.xml");
}
catch(XbrlException e)
{
Console.WriteLine("Validation Failed!");
Console.WriteLine(e.Message);
}



With today’s pattern, any exception thrown by the validation code forfeits the rest of the validation process. If a validation violation is found during the validation of unit references, for example, the context time spans, footnotes and items won’t even run through validation. Once an XBRL document is deemed invalid, then no more validation is even attempted. The analogy would be a source code compiler that stops the compilation process after the first error.


Gepsio’s Possible XBRL Validation Future


As an alternative, Gepsio could stop throwing exceptions on validation errors and simply build a list of validation errors that could be examined later. In the alternative design that I have considered (a design which is shamelessly “lifted” from the CSLA.NET business objects framework) an XBRL document loaded by Gepsio would maintain a Boolean property indicating its validity as well as a collection of validation errors. These could all be examined by the caller after Gepsio loads a document and could use this information to decide whether or not the caller can proceed with the planned operation against the loaded document. This design could make document loading look something like this:

var myDoc = new XbrlDocument();
myDoc.Load("MyXbrlDocument.xml");
if(myDoc.IsValid == false)
{
Console.WriteLine("Validation Failed!");
foreach(var validationError in myDoc.ValidationErrors)
{
Console.WriteLine(validationError);
}
}



This design takes advantage of two hypothetical additions to Gepsio’s XbrlDocument class:



  1. A read-only Boolean property called IsValid. Gepsio would set this value to true if all validation rules passed and false if at least one validation rule failed.
  2. A collection of validation error objects, with each object describing information about the error. In the simple design above, these are simple strings; however, in an actual design these may be full Gepsio-namespaced objects that describe a validation error with as much fidelity as possible to identify the root of the problem as well as the error category. Callers may want to distinguish between a unit reference error and a calculation summation error, and a simple string would not give that kind of fidelity.

In this design, no exceptions are thrown, allowing Gepsio to perform as much validation as possible.


Feedback Welcome


Your feedback is welcome. Do you like the current exception-based validation scheme? Do you favor the validity design shown above? Or do you have another idea? Add your feedback to a comment on this post or post a message to the Gepsio Facebook page at http://www.facebook.com/gepsio.

Monday, August 27, 2012

Importing XBRL Fact Values Into SQL Server Using PowerShell and Gepsio

A Gepsio user has just written in with a success story on importing XBRL data into a SQL Server database using SQL Server Integration Services (SSIS), PowerShell and Gepsio. The solution was too good not to share, and, with the user's permission, this blog post will describe that solution.

The user was tasked with importing some XBRL data into a SQL Server database instance. The overall architectural idea was to use an SSIS package to run a PowerShell script which would create a comma separated values (CSV) file from a raw XBRL document, and the values in the CSV would be used to import data into the database.

The first trick, which isn't really XBRL-specific but still worth mentioning, is to get SSIS to run a PowerShell script. Basically, PowerShell scripts are run from within an SSIS package by adding an "Execute Process Task" and using a command line in the following form:

C:\[PATHTOPOWERSHELL]\PowerShell.exe -ExecutionPolicy ByPass -command ". 'C:\SCRIPTPATH\MyScript.ps1' 'param1' 'param2'"



Read the forum discussion at http://social.msdn.microsoft.com/Forums/en-NZ/sqlintegrationservices/thread/216d2ee6-0f04-480f-808d-8241bc4a8d18 for more information about this process.


The next trick, of course, is creating the CSV file from the raw XBRL document. The user turned to PowerShell and Gepsio for this work, and life became a lot easier. Here is the example PowerShell script that can do this work:

param([string]$instFile = "C:\XBRLDOCPATH\XbrlDocument.xml")

#load Gepsio
Add-Type -Path "C:\GEPSIOPATH\JeffFerguson.Gepsio.dll"
$XbrlDoc = New-Object -TypeName JeffFerguson.Gepsio.XbrlDocument
$XbrlDoc.Load($instFile)
$instCSV = "C:\OUTPUTPATH\Allinfo.csv"

New-Item $instCSV -type "file" -force -value "EntityRegName,EntityFilerCat,FactName,Value`r`n"
$stream = new-object system.IO.StreamWriter($instCSV,$true)

[string] $script:Entity =""
try
{
foreach($CurrentFragment in $XbrlDoc.XbrlFragments)
{
GetEntityInfo $Currentfragment
try
{
WriteItemCSV $CurrentFragment "EarningsPerShareBasic"
}
catch
{
Write-Error("us-gaap_EarningsPerShareBasic: " +$_ )
}
try
{
WriteItemCSV $CurrentFragment "NetIncomeLoss"
}
catch
{
Write-Error(":us-gaap_NetIncomeLoss " +$_ )
}
}
}
catch
{
Write-Error("main foreach writeloop: " +$_ )
}
finally
{
$stream.close()
$stream.Dispose()
}

Function GetEntityInfo
{
param($fragment)
$script:Entity = ""
$entr = $fragment.Facts | Where-Object {$_.Name -eq "EntityRegistrantName"}
if(!$entr)
{
$entr = ""
}
$efc = $fragment.Facts | Where-Object {$_.Name -eq "EntityFilerCategory"}
if(!$efc)
{
$efc = ""
}
$script:Entity = "`"" + $entr.Value + "`",`"" + $efc.Value + "`","
}

Function WriteItemCSV
{
param($fragment, $ElId)
$Ff = $fragment.Facts | Where-Object {$_.Name -eq $ElId}
if($Ff)
{
[string]$S = $script:Entity
if ($Ff.GetType().fullname -eq "JeffFerguson.Gepsio.Item")
{
[string]$S = $script:Entity
if( $Ff.Name)
{
$S = $S + "`"" + $Ff.Name + "`","
}
else
{
$S = $S + "" +","
}
if( $Ff.Value)
{
$S = $S + $Ff.Value + ","
}
else
{
$S = $S + "" +","
}
$stream.WriteLine($S)
}
if ($Ff.GetType().fullname -eq "System.Object[]")
{
foreach($i in $Ff)
{
[string]$S = $script:Entity
if( $i.Name)
{
$S = $S + "`"" + $i.Name + "`","
}
else
{
$S = $S + "" +","
}
if( $i.Value)
{
$S = $S + $i.Value
}
else
{
$S = $S + ""
}
$stream.WriteLine($S)
}
}
}
}



Let's take a look at this PowerShell script in more detail.


The opening statements adds the Gepsio types to the PowerShell script and loads the XBRL document named in a PowerShell script command line parameter into a new Gepsio XbrlDocument instance:

param([string]$instFile = "C:\XBRLDOCPATH\XbrlDocument.xml")

#load Gepsio
Add-Type -Path "C:\GEPSIOPATH\JeffFerguson.Gepsio.dll"
$XbrlDoc = New-Object -TypeName JeffFerguson.Gepsio.XbrlDocument
$XbrlDoc.Load($instFile)



At this point, the PowerShell script maintains a variable called $XbrlDoc which contains all of Gepsio's knowledge about the loaded XBRL document. Loading and validating an XBRL document can't get much easier.


Once the XBRL document is loaded, then the output CSV file is created:

New-Item $instCSV -type "file" -force -value "EntityRegName,EntityFilerCat,FactName,Value`r`n"    
$stream = new-object system.IO.StreamWriter($instCSV,$true)



Here, a new file is created and the CSV column header row is written to the new file. The CSV is set up to capture the following values found in the XBRL document:



  • Entity Registrant Name
  • Entity Filer Category

A .NET StreamWriter object is created to reference the newly created CSV file and is available from within a PowerShell script variable called $stream.


Once the CSV is available, the PowerShell script iterates through each of the XBRL fragments found in the XBRL document loaded by Gepsio:

try
{
foreach($CurrentFragment in $XbrlDoc.XbrlFragments)
{
GetEntityInfo $Currentfragment
try
{
WriteItemCSV $CurrentFragment "EarningsPerShareBasic"
}
catch
{
Write-Error("us-gaap_EarningsPerShareBasic: " +$_ )
}
try
{
WriteItemCSV $CurrentFragment "NetIncomeLoss"
}
catch
{
Write-Error(":us-gaap_NetIncomeLoss " +$_ )
}
}
}
catch
{
Write-Error("main foreach writeloop: " +$_ )
}
finally
{
$stream.close()
$stream.Dispose()
}



For each XBRL fragment found in the Gepsio document instance, entity information is read and written into the CSV file. Entity information is read from the fragment, and then values are written to the CSV. These operations are performed by functions in the PowerShell script called GetEntityInfo and WriteItemCSV, respectively.


Let's take a look at the GetEntityInfo function. It is defined as follows:

Function GetEntityInfo
{
param($fragment)
$script:Entity = ""
$entr = $fragment.Facts | Where-Object {$_.Name -eq "EntityRegistrantName"}
if(!$entr)
{
$entr = ""
}
$efc = $fragment.Facts | Where-Object {$_.Name -eq "EntityFilerCategory"}
if(!$efc)
{
$efc = ""
}
$script:Entity = "`"" + $entr.Value + "`",`"" + $efc.Value + "`","
}



This function, which accepts a Gepsio XbrlFragment object as a parameter, searches through each of the fragment's facts, looking for a fact whose name is "EntityRegistrantName" or "EntityFilerCategory". If they are found, the Gepsio Fact objects are stored in local script variables -- $entr and $efc, respectively. Once the search is complete, the Fact object's values are stored as a string in a global-level script variable called $script:Entity.


The other interesting function in the PowerShell script is the WriteItemCSV function:

Function WriteItemCSV
{
param($fragment, $ElId)
$Ff = $fragment.Facts | Where-Object {$_.Name -eq $ElId}
if($Ff)
{
[string]$S = $script:Entity
if ($Ff.GetType().fullname -eq "JeffFerguson.Gepsio.Item")
{
[string]$S = $script:Entity
if( $Ff.Name)
{
$S = $S + "`"" + $Ff.Name + "`","
}
else
{
$S = $S + "" +","
}
if( $Ff.Value)
{
$S = $S + $Ff.Value + ","
}
else
{
$S = $S + "" +","
}
$stream.WriteLine($S)
}
if ($Ff.GetType().fullname -eq "System.Object[]")
{
foreach($i in $Ff)
{
[string]$S = $script:Entity
if( $i.Name)
{
$S = $S + "`"" + $i.Name + "`","
}
else
{
$S = $S + "" +","
}
if( $i.Value)
{
$S = $S + $i.Value
}
else
{
$S = $S + ""
}
$stream.WriteLine($S)
}
}
}
}



This function accepts both an Gepsio XBRL Fragment object and a fact name as parameters. It begins by searching through each of the supplied fragment's facts, looking for a fact whose name matches the supplied name. If it is found, the Gepsio Fact objects are stored in a local script variable called $Ff. If the fact is found, its name and values are appended to the global script variable $script:Entity, after which the entire line built up in the $script:Entity variable is written out to the CSV stream.



[One quick note about the placement of the functions in the PowerShell script: When the script is executed from the PowerShell command line, the functions can be found anywhere in the script. SSIS, however, may need to have the functions defined before they are used in the script. If SSIS does not execute the script as written, the functions may need to be moved forward in the script so that they are defined before they are used.]


In the end, the PowerShell script will produce a CSV file that looks something like this:

EntityRegName,EntityFilerCat,FactName,Value
"COCA COLA CO","Large Accelerated Filer","EarningsPerShareBasic",1.22
"COCA COLA CO","Large Accelerated Filer","EarningsPerShareBasic",2.05
"COCA COLA CO","Large Accelerated Filer","EarningsPerShareBasic",2.14
"COCA COLA CO","Large Accelerated Filer","EarningsPerShareBasic",1.24
"COCA COLA CO","Large Accelerated Filer","NetIncomeLoss",4703000000
"COCA COLA CO","Large Accelerated Filer","NetIncomeLoss",2788000000
"COCA COLA CO","Large Accelerated Filer","NetIncomeLoss",4842000000
"COCA COLA CO","Large Accelerated Filer","NetIncomeLoss",2800000000



Once this script is in place, the SSIS package to actually import the data becomes an easy set of two simple tasks:



  1. execute PowerShell script to create CSV from XBRL
  2. import CSV data into a database table

For the sake of brevity, the PowerShell sample shown here loads only a few XBRL values into the CSV file. In practice, however, there is no limit to the amount of data that could be loaded into the CSV.


Once all of this was working, the user sent in a testimonial that read:



"Thank you for making Gepsio available.  It saved me an awful lot of work (xpath, YIKES)!".


This is gratifying, as this is what Gepsio is all about: making access to XBRL data easier without resorting to complicated XPath queries or understanding a lot about the rules of XBRL validation or technical syntax. Gepsio provides access to XBRL data without needing to worry about XBRL itself, which frees developers to work on the more important problem of building added value on top of the data.


Many thanks go out to the Gepsio user who provided this solution.

Friday, June 22, 2012

WebException Objects and XBRL Schema Object Creation

The other day, I was doing some performance testing in Gepsio and noticed that HTTP errors found during the XBRL schema object creation process were not reported in the same way as other exceptions thrown by Gepsio.

The constructor of Gepsio’s XbrlSchema class uses an XmlTextReader to read an XBRL schema. If the URI for the XBRL schema to be read is an HTTP-based URI, then the XmlTextReader will use the .NET Web stack to read the schema using HTTP. If something fails during that process, the .NET Web stack will throw a WebException.

In the Nov 2011 CTP (and, in fact, all Gepsio CTPs to this point), thrown WebException objects were not wrapped in an XbrlException object and were consequently thrown back to the client as a WebException object.

To be clear that the issue is an XBRL issue caused by an HTTP failure, the XBRL schema creation code now creates an XbrlException object, stores the caught WebException as an inner exception to the XbrlException, and throws the XbrlException object back up to the client.

I have just checked in a fix for the issue. The fix will be available in the next release (currently planned for Jul 2012). If you want to grab the code ahead of time, feel free to grab the latest source code here.

Tuesday, June 19, 2012

Unsupported Path Bug Fixed in Linkbase Document Class

Codeplex (and Gepsio) user matthewschrager recently submitted a patch for a rather old issue that caused paths of the form "file:///C:/blah/blah/http://blah/blah.org" to be created in the LinkbaseDocument class’ GetFullLinkbasePath() method when filings that reference remote documents are stored locally. This caused a NotSupportedException to be thrown.

I have just applied this patch and have checked in a fix for the issue. The fix will be available in the next release (currently planned for Jul 2012). If you want to grab the code ahead of time, feel free to grab the latest source code here.

Many thanks to matthewschrager for sending in a patch!

Monday, June 18, 2012

Null Reference Bug Fixed in QualifiedName Class

Codeplex (and Gepsio) user jwokelly recently filed a bug noting that the Gepsio Nov 2011 CTP was failing to parse the XBRL documents created by Amazon to report their financial information for Q1 2012. More specifically, Gepsio was throwing a NullReferenceException while attempting to perform equality comparisons in the qualified name code.

I have just fixed this bug and have checked in a fix. The fix will be available in the next release (currently planned for Jul 2012). If you want to grab the code ahead of time, feel free to grab the latest source code here.

Many thanks to jwokelly for reporting a bug and for sending along the offending documents in a ZIP file. Gepsio now includes a unit test that parses these documents and ensures that no exceptions are thrown.

Sunday, June 17, 2012

Full Documentation Available for the Nov 2011 CTP

The first release of help file-style documentation for Gepsio is now available for the Nov 2011 CTP! To grab your copy, go to the Nov 2011 CTP Release page here and download the JeffFerguson.Gepsio.chm file.

If you download the file directly, and save it to a location such as your Desktop, you may get an “Navigation to the webpage was canceled” message when you open it:

image

To fix this, close the CHM file.Then find the downloaded CHM file, right click it, and select “Properties” from the context menu. You will see the file’s Properties dialog:

image

If you see the message at the bottom that reads “This file came from another computer and might be blocked to help protect this computer”, click the “Unblock” button. Click the “OK” button to close the Properties dialog, and reopen the CHM file.

Voila!

image

This online documentation is generated automatically from comments I embed in the source code. The nice part about that is that, as I update the source code comments and produce new builds, the online documentation will be updated and synchronized with the latest information available in the Gepsio object model.

Thursday, June 14, 2012

Gepsio Reviewed by HereBeDragon

I found a very nice review of Gepsio today on a blog at herebedragon.blogspot.com. Here’s what the author had to say:

My first stop was Codeplex, where I searched for the term 'XBRL' and found 3 projects. That's too few. Of these, one particularly caught my eye (in fact I have followed this project for a few months) and that is 'Gepsio'.

Gepsio is a .NET based document object model for XBRL that can load and validate XBRL documents. It's a 'strict' processor for XBRL that throws exceptions when the loaded document is not valid. Perhaps it's possible to make changes to and save XBRL files using Gepsio as well, but frankly I could not look into it in depth because of the exceptions and because I was short of time.

I did give the source code of the XBRL Reader part of Gepsio a good look though. I was impressed to see sustained work, focus on meeting XBRL conformance requirements and a clean, well organized codebase. Gepsio is a good option to evaluate if you are looking for open source XBRL software.

The Gepsio XBRL code is licensed under Microsoft Public License (Ms-PL), which allows you to use the code in a commercial application.

Find the author’s review of Gepsio, and many other open source XBRL tools, through this link.

Thanks to HereBeDragon for the review!

Monday, June 11, 2012

Gepsio on Facebook

I have just created a page for Gepsio on Facebook. “Like” Gepsio at http://www.facebook.com/gepsio to get information on releases, blog posts, documentation, samples and questions and answers. Looking forward to seeing you there!

Saturday, June 9, 2012

Documentation Work in Progress

I am currently working on providing some online help for Gepsio:

image

I am currently adding XML comments to all of the public classes, properties and methods so that I can use Sandcastle to generate CHM-style documentation. The XML comments should also aid in providing documentation to Visual Studio’s Intellisense infrastructure.

I realize that Gepsio’s growing array of public classes and properties can be daunting and I hope that this documentation will go a long away towards making its public interface understandable.

Saturday, March 24, 2012

Using Gepsio From C#

A developer new to Gepsio asked for a C#-based sample of using Gepsio. I have built a simple C# console app using Visual Studio 2010 and the Gepsio Nov 2011 CTP. I’ll show the code first, and then I will discuss some key points after the code is shown:

using JeffFerguson.Gepsio;
using System;

namespace GepsioConsole
{
class Program
{
/// <summary>
/// The magic begins here.
/// </summary>
/// <param name="args">
/// A collection of program arguments. One argument should be supplied: the address of the XBRL document
/// to load.
/// </param>
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("usage: GepsioConsole [XBRL document]");
return;
}
ProcessXbrlWithGepsio(args[0]);
}

/// <summary>
/// Process a named XBRL document.
/// </summary>
/// <param name="xbrlFile">
/// The address of the XBRL document to process.
/// </param>
private static void ProcessXbrlWithGepsio(string xbrlFile)
{
try
{
var xbrlDoc = new XbrlDocument();
xbrlDoc.Load(xbrlFile);
foreach (var currentFragment in xbrlDoc.XbrlFragments)
{
DisplayFragmentStatistics(currentFragment);
WriteFactValue(currentFragment, "EntityRegistrantName");
WriteFactValue(currentFragment, "DocumentPeriodEndDate");
}
}
catch (XbrlException xbrle)
{
Console.WriteLine("ERROR: {0}", xbrle.Message);
}
}

/// <summary>
/// Display statistics relating to the loaded document fragment.
/// </summary>
/// <param name="currentFragment">
/// The XBRL fragment whose statistics should be published.
/// </param>
private static void DisplayFragmentStatistics(XbrlFragment currentFragment)
{
var factsCollection = currentFragment.Facts;
Console.WriteLine("Number of facts...: {0}", factsCollection.Count);
var unitsCollection = currentFragment.Units;
Console.WriteLine("Number of units...: {0}", unitsCollection.Count);
var contextsCollection = currentFragment.Contexts;
Console.WriteLine("Number of contexts: {0}", contextsCollection.Count);
}

/// <summary>
/// Display the value of a fact pulled from an XBRL fragment.
/// </summary>
/// <param name="currentFragment">
/// The fragment containing the fact to be found.
/// </param>
/// <param name="factName">
/// The name of the fact to be found.
/// </param>
private static void WriteFactValue(XbrlFragment currentFragment, string factName)
{
foreach (var currentFact in currentFragment.Facts)
{
if (currentFact.Name.Equals(factName) == true)
{
var currentFactAsItem = currentFact as Item;
Console.WriteLine("{0}: {1}", factName, currentFactAsItem.Value);
return;
}
}
}
}
}



I wanted to offer a few notes regarding this code:



  • This is a console application, and is intended to be run with a command line argument specifying the address of the XBRL document to be loaded, as in GepsioConsole http://www.sec.gov/Archives/edgar/data/21344/000104746911006790/ko-20110701.xml. Gepsio can work with documents stored on the Web, so HTTP-based document addresses are valid.

  • From Gepsio’s point of view, an XBRL document is a collection of fragments. The fragments idea was originally designed to support the notion of Inline XBRL, where a document may consist of multiple XBRL fragments. For standard XBRL documents, however, the entire document is an XBRL document, which makes up one “fragment”. This explains the “for each fragment in document” code in the ProcessCodeWithGepsio() method.

  • The WriteFactValue() method looks for a fact in the fragment’s collection of facts. Remember that, from an XBRL point of view, a fact is a type of item. In XBRL parlance, items can be facts, which have a single value, or tuples, which can have more than one value. Gepsio models this fact by defining a base class called Item and then deriving both Fact and Tuple from Item. This explains the cast back to Item in the code for WriteFactValue(). The cast may look a bit strange … perhaps I’ll revisit this in a later CTP.

As I developed this sample, I noticed that Gepsio performs as intended but, for larger documents, its performance can be improved. I’ll be addressing this shortly. Look for a future blog post where I discuss performance, where it could be improved, and how the improvements will be implemented. I will be using the code in this blog post as the showcase for the performance improvements, so you will be seeing this code again.

Thursday, February 23, 2012

Gepsio Entered Into XBRL US Challenge

The folks over at XBRL US have launched a contest called the XBRL Challenge, which they have billed as "a contest that invites participants to contribute open source analytical applications for investors that leverage corporate XBRL data". I have entered Gepsio into the contest. I really don't think it has a chance to win, since it's more of an "engine" or "framework" than a full ready-to-use application, but I figured that the exposure might be a good thing.

The judges have asked all of us entrants to answer a couple of questions about our perception of our entries to the contest, and I thought that I would share my answers here:
What deficiency or opportunity did you see - with respect to published financial data analysis - that drove your idea for an application using XBRL?The relatively high barrier to entry. Building an XBRL-aware application today means that XML parsing code must be written, after which the XBRL validation rules must be encoded and tested. The opportunity I see with Gepsio is one in which the parsing and validation logic is packaged in a ready-to-use assembly that can be picked up and used by others to build application and value-added logic, thereby dramatically lowering the barrier to entry for XBRL developers. It also opens the door for PowerShell users to write “XBRL scripts” without ever encoding low-level XML and XBRL details.

What was the moment you enjoyed most during this competition?I have enjoyed seeing Gepsio used and embraced by others. I put Gepsio up on Codeplex to little fanfare, unsure of what might become of it. To see it used by others – to see the project followed by other users on Codeplex; to see Gepsio mentioned in XBRL answers on the Stack Overflow Web site; to get emails from people using it – all of it makes the effort worthwhile. It’s validation that what Gepsio offers fills a need as yet untapped by the current developer tool space, and that is very gratifying.
The winner of the contest is judged by a panel of judges, although a People's Choice vote is also being held for another week or so. If you feel compelled to vote for Gepsio in this People's Choice competition, head on over to the XBRL US Challenge page and click on the "Vote for the Best XBRL App" link in the upper right-hand section titled "XBRL Challenge Judges".

Good luck to all Challenge participats!

Friday, January 6, 2012

Gepsio Nov 2011 CTP and iXBRL

In the discussion located here, a gentleman asked about Gepsio's support for iXBRL after noting that iXBRL is coming up to speed in the UK. I mentioned that I would look into it, noting that I had structured Gepsio in such a way that a document was a collection of XBRL fragments, and that the design was put in place specifically to handle multiple XBRL fragments in a document, thereby supporting the iXBRL model of XBRL embedded within a larger XML document whose root was not necessarily an XBRL root.

The gentleman with whom I had the conversation was very generous in supplying some iXBRL documents with which I could test Gepsio, and I used the following PowerShell script to load the sample and see what I could find out at a high level:

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

$XbrlDoc = New-Object -TypeName JeffFerguson.Gepsio.XbrlDocument
$DocumentLocation = "sample-ixbrl.xml"

Write-Host "Loading and validating" $DocumentLocation"..."
$XbrlDoc.Load($DocumentLocation)
Write-Host "Loaded." $XbrlDoc.XbrlFragments.Count "fragments in document."

foreach($XbrlFragment in $XbrlDoc.XbrlFragments)
{
    Write-Host $XbrlFragment.Facts.Count "facts in fragment."
    Write-Host $XbrlFragment.Units.Count "units in fragment."
    Write-Host $XbrlFragment.Contexts.Count "contexts in fragment."
    WriteItemAndValue $XbrlFragment "EntityRegistrantName"
    WriteItemAndValue $XbrlFragment "TradingSymbol"
    WriteItemAndValue $XbrlFragment "DocumentPeriodEndDate"
}

Function WriteItemAndValue
{
    param($fragment, $name)
    $FoundItem = $fragment.Facts | Where-Object { $_.Name -eq $name }
    Write-Host $name ": " $FoundItem.Value
}
As it turns out, I have good news and bad news:
  • The good news is that Gepsio parses the ful document at the XML level without errors, even when the root of the XML document is not an <xbrl> root.
  • The bad news is that Gepsio didn't find any XBRL fragments in the supplied document, despite the document's valid iXBRL tagging.
Gepsio makes an assumption that iXBRL fragments are marked up using the same schema as a full XBRL document, which is not the case. The iXBRL tagging structure, documented here, is not supported by Gepsio in the Nov 2011 CTP, and it will be my job to correct that flaw.

My plan is to work on Gepsio's iXBRL support this month to see how far I get. I hope to report back on my progress soon. In my ideal world, I would like to release a new CTP of Gepsio this month that includes iXBRL support.

Wish me luck!