title: Reading XBRL facts - Java
body: <p>I need to get a few facts from SEC 10-K filings for e.g. gross revenue, gross profit, gross margin, operating expenses etc. along with the corresponding context.</p>
  
  <p>For filings like <a href="https://www.sec.gov/Archives/edgar/data/1318605/000156459018002956/tsla-20171231.xml" rel="noreferrer">https://www.sec.gov/Archives/edgar/data/1318605/000156459018002956/tsla-20171231.xml</a> , it seems feasible to just use XPath to find out the few required elements and the values.
  But there are filings like (<a href="https://www.sec.gov/Archives/edgar/data/19617/000001961718000057/jpm-20171231.xml" rel="noreferrer">https://www.sec.gov/Archives/edgar/data/19617/000001961718000057/jpm-20171231.xml</a>) where total expense is broken up in different segments with an extension taxonomy.</p>
  
  <p>My question is </p>
  
  <ol>
  <li>What would be a reliable way to work with files like these? Say, if I just want the total operational expenditure. Is there a reliable way to find what are the elements I'll need to read and then may be sum up?</li>
  <li>I've tried using the UBMatrix library for reading xbrl files. It works on some files (non-SEC, can read node values) but for SEC 10-K filings throws NPE. Could there be a particular reason why xbrls instance documents from SEC is failing? (haven't checked library code though)</li>
  </ol>
  
  <p>In any case, if doing it simply with XPath is possible I'd prefer that.
  Validity of the xbrl document is not important.</p>