javascript - Parse XBRL file with JS - Stack Overflow

I want to parse XBRL files such as this one thus I found this npm module that purports to be able to pa

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=".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 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.

Share Improve this question asked Aug 10, 2017 at 23:44 BWPBWP 3902 silver badges17 bronze badges 2
  • Have you made sure that the module is installed locally? – Programah Commented Aug 11, 2017 at 0:57
  • Yes, I am running my code through an IDE and installed my module through the mand prompt – BWP Commented Aug 11, 2017 at 2:24
Add a ment  | 

3 Answers 3

Reset to default 3

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.

For anyone else seeing this, I'm the author, so I wanted to clear up some confusion. I incorrectly documented the first function as parseFile, the actual name is parse. I've updated the readme to be correct. This function doesn't load a document over https (although that would be a great enhancement), it expects the file to exist as a hard copy. As far as not being very flexible in accepted document format, prs wele. The test files I use are all taken from the SEC edgar site.

(Disclaimer: While I am familiar with XBRL, I am not familiar with this specific library.)

From what I understand from the documentation, this module has two functions:

  • parseFile, which takes the location of an XBRL instance
  • parseStr, which takes the contents, as a string, of an actual XBRL instance (which has the XML format)

The above snippet is calling parseStr, but the XBRL instance passed as a string looks incorrect: it is an empty element, it passes the location of the Apple filing as a namespace declaration, and a space is missing after xbrli:xbrl and before the namespace binding (which makes it non-namespace-well-formed XML).

I am under the impression that the intent of the module is to use parseFile instead, like so:

var ParseXbrl = require('parse-xbrl');

ParseXbrl.parseFile('https://www.sec.gov/Archives/edgar/data/320193/000162828016020309/aapl-20160924.xml').then(function(parsedDoc) {
  // Use results...
});

This is assuming that it is capable of fetching the instance over the Web. Otherwise, the instance (aapl-20160924.xml) should probably be copied locally and parseFile invoked with a local file location instead (on the documentation page, this is a relative file location).

Another alternative is to call parseStr and copy-and-paste the contents of aapl-20160924.xml as its parameter, but I do not think that it would be best practice to pass such as long string, especially as it may contain single quotes (this very instance does contain a few).

As a final remark, I tried to copy-and-paste the contents of this instance (Apple's Q4 for 2016) into the module's Web interface, but it did not seem to accept it as XML/XBRL, even though, as you correctly state, this instance is indeed correct and valid XBRL. I managed to make it work with only a subset of the instance (with only the first context and the DEI facts), so it may be that there is a bug to report.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744724050a4590080.html

相关推荐

  • javascript - Parse XBRL file with JS - Stack Overflow

    I want to parse XBRL files such as this one thus I found this npm module that purports to be able to pa

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信