Home Forums Support Import OFX file: Failed to parse OFX file

This topic contains 4 replies, has 2 voices, and was last updated by  Hillel Coren 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17561

    nico
    Participant

    Hi there,

    I got the error “Failed to parse OFX file” after attempting to upload OFX file downloaded from ING Direct Australia.

    Below is my OFX file content:

    OFXHEADER:100
    DATA:OFXSGML
    VERSION:102
    SECURITY:NONE
    ENCODING:USASCII
    CHARSET:1252
    COMPRESSION:NONE
    OLDFILEUID:NONE
    NEWFILEUID:NONE
    <OFX>
    <SIGNONMSGSRSV1>
    <SONRS>
    <STATUS>
    <CODE>0
    <SEVERITY>INFO
    </STATUS>
    <DTSERVER>20181217111357
    <LANGUAGE>ENG
    </SONRS>
    </SIGNONMSGSRSV1>
    <BANKMSGSRSV1>
    <STMTTRNRS>
    <TRNUID>1
    <STATUS>
    <CODE>0
    <SEVERITY>INFO
    </STATUS>
    <STMTRS>
    <CURDEF>AUD
    <BANKTRANLIST>
    <STMTTRN>
    <TRNTYPE>CREDIT
    <DTPOSTED>20181214000000
    <TRNAMT>337.50
    <FITID>****17
    <MEMO>J E LI****      Beau & Rhiannon  - Receipt ****17
    </STMTTRN>
    ...
    </BANKTRANLIST>
    </STMTRS>
    </STMTTRNRS>
    </BANKMSGSRSV1>
    </OFX>

    Any help would be much appreciated.

    Thanks
    Nico

    • This topic was modified 9 months, 1 week ago by  nico.
    #17564

    nico
    Participant

    Below is the log associated the error described previously.

    [2018-12-17 01:55:00] production.ERROR: ***RuntimeException*** [0] : /home/donnangc/invoice.donnang.com.au/vendor/asgrim/ofxparser/lib/OfxParser/Parser.php 
    [Line 83] => Failed to parse OFX: array (   
    0 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 27,   )),   
    1 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 321,   )),   
    2 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 405,   )),   
    3 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 594,   )),   
    4 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 860,   )),   
    5 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 944,   )),   
    6 =>    LibXMLError::__set_state(array(      'level' => 3,      'code' => 68,      'column' => 30,      'message' => 'xmlParseEntityRef: no name ',      'file' => '',      'line' => 993,   )), )  
    {"context":"PHP","user_id":1,"account_id":"1","user_name":"Nico","method":"POST","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36","locale":"en_GB","ip":"***.***.***.***","count":2,"is_console":"no","is_api":"no","db_server":"mysql","url":"bank_accounts/import_ofx"} []
    #17565

    Hillel Coren
    Keymaster

    Are you using invoiceninja.com or are you self hosting?

    #17609

    nico
    Participant

    Hi Hillel,

    It’s self-hosted, version 4.5.1 and installed with Softaculous.

    I dug a little and discovered that SGML string cannot be parsed into XML string because of the presence of special characters in the memo tag. When a tag value contains the at sign (@), the double quote sign (“), the inferior sign (<), the superior sign (>) and/or the hat sign (^), the parser fails.

    Not sure if those characters are supposed to be in the OFX file but I have created a patch to convert @ and ” into their respective html codes and the XML parsing comes out nicely. However, I couldn’t make it work with <, > (which I assumed shouldn’t be in the OFX file) and ^.

    Below is the code added to invoiceninja/vendor/asgrim/ofxparser/lib/OfxParser/Parser.php at line 120:

    $sgml=preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $sgml);

    Then the function createDateTimeFromStr from OFX.php returned

    ***RuntimeException*** [0] : /Users/nic/Sites/ninja/vendor/asgrim/ofxparser/lib/OfxParser/Ofx.php 
    [Line 295] => Failed to initialize DateTime for string:   

    Some of the fields passed on to this function didn’t exist so I had to test beforehand that the $dateString was set and had a value.

    Below is the code added to invoiceninja/vendor/asgrim/ofxparser/lib/OfxParser/Ofx.php at line 268:

    if((!isset($dateString) || trim($dateString) === '')) return null;

    • This reply was modified 9 months ago by  nico.
    #17611

    Hillel Coren
    Keymaster

    It looks like a similar fix was added in a newer version of the OFX library we’re using.

    https://github.com/asgrim/ofxparser/commit/02aef21c495d1382ce87e7f23af1a8acd354c5f0

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Posted in: