http://blog.csdn.net/qustmeng/article/details/53706657
- try{
- JAXBContextcontext=JAXBContext.newInstance(Entity.class);
- Marshallermarshaller=context.createMarshaller();
- //xml格式
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
- //去掉生成xml的默认报文头
- marshaller.setProperty(Marshaller.JAXB_FRAGMENT,0); background-color:inherit">//不进行转义字符的处理
- marshaller.setProperty(CharacterEscapeHandler.class.getName(),newCharacterEscapeHandler(){
- publicvoidescape(char[]ch,153); font-weight:bold; background-color:inherit">intstart,153); font-weight:bold; background-color:inherit">intlength,153); font-weight:bold; background-color:inherit">booleanisAttVal,Writerwriter)throwsIOException{
- writer.write(ch,start,length);
- }
- });
- StringWritersw=newStringWriter();
- marshaller.marshal(entity,sw);
- returnsw.toString();
- }catch(JAXBExceptione){
- log.error("",e);
- }
原文地址:https://www.jb51.cc/xml/293606.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。