Java XML JAXB Object to XML getXmlString(T jaxbObject)

Here you can find the source of getXmlString(T jaxbObject)

Description

get Xml String

License

Apache License

Declaration

public static <T> String getXmlString(T jaxbObject) throws JAXBException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    public static <T> String getXmlString(T jaxbObject) throws JAXBException {
        StringWriter sw = new StringWriter();
        JAXBContext context = JAXBContext.newInstance(jaxbObject.getClass());
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(jaxbObject, sw);/*  w  w  w  .  j a v  a  2 s  .c o  m*/
        return sw.toString();
    }
}

Related

  1. createXML(Object o)
  2. getObjects(List> objEls)
  3. getObjects(List objEls)
  4. getXmlString(JAXBElement versioningInfo, Boolean formatXml, Schema schema)
  5. getXMLString(Object person, Class clazz)
  6. Object2Xml(Object object)
  7. objectToXML(Class cls, Object entity)
  8. ObjectToXml(Object object)
  9. objectToXml(Object source, Class... type)