Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import javax.xml.validation.Schema;

import java.io.ByteArrayOutputStream;

public class Main {
    public static String getXmlString(JAXBElement versioningInfo, Boolean formatXml, Schema schema)
            throws JAXBException {
        String packageName = versioningInfo.getValue().getClass().getPackage().getName();
        JAXBContext context = JAXBContext.newInstance(packageName);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatXml);

        if (schema != null) {
            marshaller.setSchema(schema);
        }

        ByteArrayOutputStream oStream = new ByteArrayOutputStream();
        marshaller.marshal(versioningInfo, oStream);

        return oStream.toString();
    }
}