-
Notifications
You must be signed in to change notification settings - Fork 26
Validating XBRL Instances
In addition to parsing XBRL instances, Gepsio also validates the instance's contents according to the XBRL specification. Gepsio can report on whether or not the loaded instance is valid according to the specification, and, if the instance is invalid, can offer information about the errors.
The XbrlDocument
class maintains a Boolean property called IsValid
which will, after an XBRL instance is loaded, describe whether or not the loaded document is valid according to the specification. If the value of IsValid
is true
, then the instance is valid. If the value of IsValid
is false
, then the instance is invalid.
If the document instance is invalid, then you can examine an XbrlDocument
property called ValidationErrors
to get more information about why the loaded instance is invalid. The ValidationErrors
property is a list of objects of type JeffFerguson.Gepsio.ValidationError
. The ValidationError
class maintains a string property called Message
which describes the validation error.
If Gepsio determines that a document instance is invalid, it still provides the same object model that it provides for a valid instance. Code should still be able to traverse the document's fragments, schemas, facts, and other entities, provided that the necessary level of information could still be loaded. If IsValid
evaluates to false
for a loaded document instance, code does not need to assume that there is no object model information is available. The only issue is that, depending on the type of errors that were encountered during validation, some of the information in the object model may be inaccurate or incorrect.
using JeffFerguson.Gepsio;
using System;
namespace ValidityChecks
{
class Program
{
static void Main(string[] args)
{
var xbrlDoc = new XbrlDocument();
xbrlDoc.Load(@"..\..\JeffFerguson.Gepsio.Test\XBRL-CONF-2014-12-10\Common\300-instance\301-01-IdScopeValid.xml");
CheckValidity(xbrlDoc);
}
static void CheckValidity(XbrlDocument doc)
{
if(doc.IsValid == true)
{
Console.WriteLine("Congratulations! This document is valid according to the XBRL specification.");
}
else
{
Console.WriteLine("This document is invalid according to the XBRL specification.");
foreach(var validationError in doc.ValidationErrors)
{
Console.WriteLine(validationError.Message);
}
}
}
}
}
Imports System
Imports JeffFerguson.Gepsio
Module Program
Sub Main(args As String())
LoadValidInstance()
LoadInvalidInstance()
End Sub
Private Sub LoadValidInstance()
Dim xbrlDoc = New XbrlDocument()
xbrlDoc.Load("..\..\..\..\..\..\JeffFerguson.Gepsio.Test\XBRL-CONF-2014-12-10\Common\300-instance\301-01-IdScopeValid.xml")
CheckValidity(xbrlDoc)
End Sub
Private Sub LoadInvalidInstance()
Dim xbrlDoc = New XbrlDocument()
xbrlDoc.Load("..\..\..\..\..\..\JeffFerguson.Gepsio.Test\XBRL-CONF-2014-12-10\Common\300-instance\301-10-FootnoteFromOutOfScope.xml")
CheckValidity(xbrlDoc)
End Sub
Private Sub CheckValidity(xbrlDoc As XbrlDocument)
If xbrlDoc.IsValid = True Then
Console.WriteLine("Congratulations! This document is valid according to the XBRL specification.")
Else
Console.WriteLine("This document is invalid according to the XBRL specification.")
For Each ValidationError In xbrlDoc.ValidationErrors
Console.Write(ValidationError.Message)
Next
End If
End Sub
End Module
open System
open JeffFerguson.Gepsio
let CheckValidity (xbrlDoc : XbrlDocument) =
if xbrlDoc.IsValid then
Console.WriteLine "Congratulations! This document is valid according to the XBRL specification."
else
Console.WriteLine "This document is invalid according to the XBRL specification."
for validationError in xbrlDoc.ValidationErrors do
Console.WriteLine validationError.Message
|> ignore
let LoadValidInstance =
let xbrlDoc = new XbrlDocument()
xbrlDoc.Load @"..\..\..\..\..\..\JeffFerguson.Gepsio.Test\XBRL-CONF-2014-12-10\Common\300-instance\301-01-IdScopeValid.xml"
CheckValidity xbrlDoc
|> ignore
let LoadInvalidInstance =
let xbrlDoc = new XbrlDocument()
xbrlDoc.Load @"..\..\..\..\..\..\JeffFerguson.Gepsio.Test\XBRL-CONF-2014-12-10\Common\300-instance\301-10-FootnoteFromOutOfScope.xml"
CheckValidity xbrlDoc
|> ignore
[<EntryPoint>]
let main argv =
LoadValidInstance
LoadInvalidInstance
0 // return an integer exit code