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解析一样,正常不过,是很正常的序列化格式。

  • 相关阅读:
    Scala window下安装
    HIVE 总结
    mapreduce源码解析以及优化
    Hadoop2.x + eclipse 插件配置
    python spark
    Hive与Hbase关系整合
    Sqoop架构以及应用介绍
    flume
    SOAP
    Leetcode#75 Sort Colors
  • 原文地址:https://www.cnblogs.com/panxuejun/p/7623865.html
Copyright © 2011-2022 走看看