How to produce XML signature with no whitespaces and line-breaks in Java?

前端 未结 8 1576
情话喂你
情话喂你 2020-12-17 00:51

I work with the brazilian \"Nota Fiscal Eletronica\" project, in which they define a standart way to sign XML documents.

Recently, they started to require that there

8条回答
  •  抹茶落季
    2020-12-17 01:45

    We just need to set the "true" value to the "ignoreLineBreaks" parameter, cause' the default value is false and this allows to the signature API to add LineBreaks

    here is the code to avoid or remove LineBreaks

    Field f = XMLUtils.class.getDeclaredField("ignoreLineBreaks");
    f.setAccessible(true);
    f.set(null, Boolean.TRUE);
    

    then, we'll can make sure that the new value is true with the next code line

    System.err.println(XMLUtils.ignoreLineBreaks());
    

    I had the same problem and this worked for me.

提交回复
热议问题