zoukankan      html  css  js  c++  java
  • xml解析工具mashaller javaee自带解析类

    1.怎样去掉Marshaller的格式化?

    1. JAXBContext context = JAXBContext.newInstance(Entity.class);  
    2.             Marshaller marshaller = context.createMarshaller();  
    3.             // xml格式  
    4.             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);  
    5.             // 去掉生成xml的默认报文头  
    6.             marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);  
    7.             // 不进行转义字符的处理  
    8.             marshaller.setProperty(CharacterEscapeHandler.class.getName(), new CharacterEscapeHandler() {  
    9.                 public void escape(char[] ch, int start,int length, boolean isAttVal, Writer writer) throws IOException {  
    10.                     writer.write(ch, start, length);  
    11.                 }  
    12.             });  
    13.             StringWriter sw = new StringWriter();  
    14.             marshaller.marshal(entity, sw);  
    15.             return sw.toString();  
    16.         } catch (JAXBException e) {  
    17.             log.error("", e);  
    18.         }  

    2.xml就像json解析一样,正常不过,是很正常的序列化格式。

  • 相关阅读:
    python 返回函数的使用
    你的服务器还在裸奔吗?
    云计算产品vSwitch原理
    网卡创建Bond
    UI自动化框架介绍
    常用底层linux命令
    Linux Bridge基本概念
    磁盘格式化及设置自动挂载
    Linux vi文本编辑器常用命令
    MySQL5.7安装方式
  • 原文地址:https://www.cnblogs.com/panxuejun/p/7623865.html
Copyright © 2011-2022 走看看