1. How do I get rid of marshaller formatting?
:
- Jaxbcontext context = Jaxbcontext.newinstance (Entity. Class);
- Marshaller Marshaller = Context.createmarshaller ();
- //XML format
- Marshaller.setproperty (Marshaller.jaxb_formatted_output, true);
- //Remove the default headers that generate XML
- Marshaller.setproperty (Marshaller.jaxb_fragment, true);
- //non-escape character handling
- Marshaller.setproperty (Characterescapehandler. Class.getname (), new Characterescapehandler () {
- public void Escape (char[] ch, int start,int length, boolean isattval, writer writer) throws IO Exception {
- Writer.write (CH, start, length);
- }
- });
- StringWriter SW = new StringWriter ();
- Marshaller.marshal (entity, SW);
- return sw.tostring ();
- } catch (Jaxbexception e) {
- Log.error ("", e);
- }
2.xml, like JSON parsing, is normal, but it's a normal serialization format.
XML parsing tool mashaller Java EE comes with parsing class