xml解析工具mashaller javaee自帶解析類
阿新 • • 發佈:2017-10-03
for writer length star 工具 進行 去掉m comm err
1.怎樣去掉Marshaller的格式化?
:
- JAXBContext context = JAXBContext.newInstance(Entity.class);
- Marshaller marshaller = context.createMarshaller();
- // xml格式
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- // 去掉生成xml的默認報文頭
- 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自帶解析類