A Gepsio user has requested the ability to load XBRL instances from a stream, as opposed to specifying a physical file name. I am happy to report that the functionality has been added to Gepsio, and that it will be available in the next CTP. The Load() method to the XbrlDocument class now supports an additional signature:
bool Load(Stream streamedXbrl);
Gepsio supports streams using the .NET Stream base class, which means that any type of stream supported by .NET and having the Stream class as a base class will be supported by Gepsio. This means that code like this will work:
// an admittedly contrived example, since URIs are already supported by // the original Load() method, but ... you get the point. var webClient = new WebClient(); string readXml = webClient.DownloadString("http://www.xbrl.org/taxonomy/int/fr/ias/ci/pfs/2002-11-15/SampleCompany-2002-11-15.xml"); byte byteArray = Encoding.ASCII.GetBytes(readXml); MemoryStream memStream = new MemoryStream(byteArray); var newDoc = new XbrlDocument(); newDoc.Load(memStream);
There is just one catch, and that has to do with the schema references. Schema references found in streamed XBRL instances must specify an absolute location, and not a relative location. For example, this schema reference is fine:
However, this one is not:
<xbrll:schemaRef xlink:href="msft-20141231.xsd" ... />
The reason behind this restriction is that Gepsio must load schema references using an absolute location, and uses the location of the XBRL document instance as the reference path when resolving schema relative paths to an absolute location. A schema reference without a path, for example, says “find this schema in the same location as the XBRL document instance referencing the schema”. When the XBRL document instance is located through a file path or URL, then the location is known, and the schema reference can be found. When the XBRL document instance is passed in as a stream, however, the instance has no location, per se. Since it has no location, there is no “location starting point” for resolving schema locations using relative paths.
If you try to load an XBRL document instance through a stream, and that stream references a schema through a relative path, then the document will be marked as invalid when the Load() method returns. This code, for example, will load an invalid document instance, since the XBRL document instance references a schema through a relative path:
var webClient = new WebClient(); string readXml = webClient.DownloadString("http://www.sec.gov/Archives/edgar/data/789019/000119312515020351/msft-20141231.xml"); byte byteArray = Encoding.ASCII.GetBytes(readXml); MemoryStream memStream = new MemoryStream(byteArray); var newDoc = new XbrlDocument(); newDoc.Load(memStream); // newDoc.IsValid property will be FALSE here. Sad face.
The document’s ValidationErrors collection will contain a SchemaValidationError object, which will contain a message similar to the following:
“The XBRL schema at msft-20141231.xsd could not be read because the file could not be found. Because the schema cannot be loaded, some validations will not be able to be performed. Other validation errors reported against this instance may stem from the fact that the schema cannot be loaded. More information on the “file not found” condition is available from the validation error object’s inner exception property.”
XBRL document instances loaded through a stream which use absolute paths for schema references will be valid (assuming that all of the other XBRL semantics in the instance are correct).