admin管理员组文章数量:1391955
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
3 Answers
Reset to default 3I 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.
本文标签: javascriptParse XBRL file with JSStack Overflow
版权声明:本文标题:javascript - Parse XBRL file with JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744724049a2621866.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论