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); @H_404_114@returnsw.toString();
- }catch(JAXBExceptione){
- log.error("",e);
- }