Java XML JAXB Marshaller marshallXMLInConsole(Object obj)

Here you can find the source of marshallXMLInConsole(Object obj)

Description

marshall XML In Console

License

Apache License

Declaration

public static void marshallXMLInConsole(Object obj) 

Method Source Code


//package com.java2s;
/*/*from   w w w  .j  ava  2s  .com*/
Copyright 2013 International Maize and Wheat Improvement Center
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

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

public class Main {
    public static void marshallXMLInConsole(Object obj) {

        try {
            JAXBContext context = JAXBContext.newInstance(obj.getClass());
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(obj, System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. marshallObjectAsString(Class clazz, T object)
  2. marshallObjectToXML(final Object jaxbModel, final URL schemaURL)
  3. marshallToString(Object jaxbElement, Class c)
  4. marshallToXml(String zpackage, Writer writer, Object data)
  5. marshallXml(final Object object)
  6. marshalObject(Object obj, File file)
  7. marshalObjectToXml(Object object, String xmlFilePath)
  8. marshalPackage(OutputStream printStream, final Package p)
  9. marshalToString(Object obj)