Menu

#28 Save xml in default charset, but not in utf-8

open
jConfig (29)
5
2021-04-06
2006-02-13
Igorek
No

Save xml in default charset, but need utf-8.

to configuration i write russian text.

my code:

XMLFileHandler handler = new
XMLFileHandler(fileConfiguration.getAbsolutePath());
handler.setEncoding("UTF-8");
handler.store(configuration);

after save file, i try load him:

org.jconfig.ConfigurationManagerException: The parser
cannot parse the file: Invalid byte 2 of 2-byte UTF-8
sequence.
at org.jconfig.handler.XMLFileHandler.
load(XMLFileHandler.java:115)
at org.jconfig.handler.XMLFileHandler.
load(XMLFileHandler.java:69)

Discussion

  • Andreas Mecky

    Andreas Mecky - 2006-03-07

    Logged In: YES
    user_id=355897

    Please try to use configuration.setEncoding("UTF-8") instead
    of setting the encoding for the handler. This should work.
    At least it worked for me.

     
  • Andreas Mecky

    Andreas Mecky - 2006-03-07
    • assigned_to: nobody --> amecky
     
  • Terry R. Dye

    Terry R. Dye - 2006-06-09

    Logged In: YES
    user_id=317423

    Did the last comment help solve the problem? If yes, then we
    can close this bug/issue.

    Thanks for any info.

     
    • Georg

      Georg - 2021-04-06

      No, the problem is still there, at least under Microsoft Windows. If I store a German umlaut like ä, ö, ü or ß, the file is corrupted using the XMLFileHandler.store() method. You can double check with Notepad++, etc. This file cannot be loaded, I get:
      Uncaught exception occured at Tue Apr 06 16:03:50 CEST 2021:
      org.jconfig.ConfigurationManagerException: The parser cannot parse the file: Invalid byte 2 of 3-byte UTF-8 sequence.
      at org.jconfig.handler.XMLFileHandler.load(XMLFileHandler.java:122)
      at org.jconfig.handler.XMLFileHandler.load(XMLFileHandler.java:78)

      Under Linux the config file is written correctly including German umlauts. Doesn't matter if you use set the handler encoding, the configuration encoding or both to "UTF-8" or none of them.

       

Log in to post a comment.

MongoDB Logo MongoDB