I want to parse XBRL files such as this one thus I found this npm module that purports to be able to parse XBRL files. This is my implementation of the example code:
var ParseXbrl = require('parse-xbrl');
ParseXbrl.parseStr('<?xml version="1.0" encoding="US-ASCII"?> <xbrli:xbrlxmlns:aapl="https://www.sec.gov/Archives/edgar/data/320193/000162828016020309/aapl-20160924.xml">').then(function(parsedString) {
console.log(parsedString);
});
However it returns just the following:
Field not found. is not a date
loaded EntityRegistrantName: Field not found.
loaded CurrentFiscalYearEndDate: Field not found.
loaded EntityCentralIndexKey: Field not found.
loaded EntityFilerCategory: Field not found.
loaded TradingSymbol: Field not found.
loaded DocumentPeriodEndDate: Field not found.
loaded DocumentFiscalYearFocus: Field not found.
loaded DocumentFiscalPeriodFocus: Field not found.
loaded DocumentFiscalYearFocusContext: Field not found.
loaded DocumentFiscalPeriodFocusContext: Field not found.
loaded DocumentType: Field not found.
Unhandled rejection No year end found.
I have my doubts that there is something wrong with the doocument itself as it is straight from the SEC and since I have tested multiple different documents (each with the same lackluster results), thus either my code is incorrect or the npm module is outdated or faulty. My question is thus, what is the correct code I should be using, or alernatively, what is the correct npm module I should be using (if any).
Any help is greatly appreciated.
I had the same problem with .parseFile not working so I cam up with a clever work around:
var ParseXbrl = require('parse-xbrl');
var request = require("request");
var XML = "";
request
.get('https://www.sec.gov/Archives/edgar/data/320193/000162828016020309/aapl-20160924.xml')
.on('response', function(response) {
response.on('data', function(chunk){
XML += chunk;
});
response.on('end',function(){
ParseXbrl.parseStr(XML).then(function(parsedDoc) {
console.log(parsedDoc);
});
});
});
Here I use an HTTP request to get the XML and then I have the XBRL module parse that data as a string.