1.怎样去掉Marshaller的格式化?
:
- JAXBContext context = JAXBContext.newInstance(Entity.class);
- Marshaller marshaller = context.createMarshaller();
-
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-
- marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
-
- marshaller.setProperty(CharacterEscapeHandler.class.getName(), new CharacterEscapeHandler() {
- public void escape(char[] ch, int start,int length, boolean isAttVal, Writer writer) throws IOException {
- writer.write(ch, start, length);
- }
- });
- StringWriter sw = new StringWriter();
- marshaller.marshal(entity, sw);
- return sw.toString();
- } catch (JAXBException e) {
- log.error("", e);
- }
2.xml就像json解析一样,正常不过,是很正常的序列化格式。
xml解析工具mashaller javaee自带解析类
原文:http://www.cnblogs.com/panxuejun/p/7623865.html