XML报文拼接 乱码

以下直接上源码:

/*Element root = doc.getRootElement();
        Element ACCOUNTLISTElement = new Element("ACCOUNTLIST");
        Element ACCOUNTElement = new Element("ACCOUNT");

        String mobile = autoRegistVo.getMOBILE();

        Element ACCOUNTNAMEElement = new Element("ACCOUNTNAME");
        ACCOUNTNAMEElement.addContent(mobile);
        ACCOUNTElement.addContent(ACCOUNTNAMEElement);

        Element ACCOUNTPWDElement = new Element("ACCOUNTPWD");
//        ACCOUNTPWDElement.addContent(" ");
        ACCOUNTElement.addContent(ACCOUNTPWDElement);

        Element ACCOUNTTYPEElement = new Element("ACCOUNTTYPE");
//        ACCOUNTTYPEElement.addContent(" ");
        ACCOUNTElement.addContent(ACCOUNTTYPEElement);

        Element AGENTIDElement = new Element("AGENTID");
        OfficeAccountEntity officeAccount = super.findOfficeAccount(mobile);
        if (officeAccount != null) {
            AGENTIDElement.addContent(officeAccount.getOfficeId());
        }
        ACCOUNTElement.addContent(AGENTIDElement);

        Element ISAUTOREGISTElement = new Element("ISAUTOREGIST");
//        ISAUTOREGISTElement.addContent(" ");
        ACCOUNTElement.addContent(ISAUTOREGISTElement);

        Element FIRSTLOGINTIMEElement = new Element("FIRSTLOGINTIME");
//        FIRSTLOGINTIMEElement.addContent(" ");
        ACCOUNTElement.addContent(FIRSTLOGINTIMEElement);

        Element FIRSTLOGINTYPEElement = new Element("FIRSTLOGINTYPE");
//        FIRSTLOGINTYPEElement.addContent("");
        ACCOUNTElement.addContent(FIRSTLOGINTYPEElement);

        Element ISBINDPOLICYElement = new Element("ISBINDPOLICY");
//        ISBINDPOLICYElement.addContent(" ");
        ACCOUNTElement.addContent(ISBINDPOLICYElement);

        ACCOUNTLISTElement.addContent(ACCOUNTElement);
        root.addContent(ACCOUNTLISTElement);

        String xmlStr = "";
        try {
            org.jdom2.output.Format format = org.jdom2.output.Format.getCompactFormat();
            format.setEncoding("UTF-8");// 设置xml文件的字符为UTF-8,解决中文问题

            XMLOutputter xmlout = new XMLOutputter(format);

            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            xmlout.output(doc, bo);
            xmlStr = new String(bo.getByteArray(),"UTF-8")
       //xmlStr = bo.toString(); } catch (Exception e) { logger.error("补充认证中心xml结果失败"); } return xmlStr;
*/ //return JsonUtils.transferToJson(convertRegistFileToXml(registAccountExeitModel));
原文地址:https://www.cnblogs.com/otways/p/11158753.html