Java XML JAXB Object to XML getXmlString(JAXBElement versioningInfo, Boolean formatXml, Schema schema)

Here you can find the source of getXmlString(JAXBElement versioningInfo, Boolean formatXml, Schema schema)

Description

get Xml String

License

Apache License

Declaration

public static String getXmlString(JAXBElement versioningInfo, Boolean formatXml, Schema schema)
            throws JAXBException 

Method Source Code


//package com.java2s;
/*//  ww w .ja v a 2  s. co m
 * _=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
 * Repose
 * _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
 * Copyright (C) 2010 - 2015 Rackspace US, Inc.
 * _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
 * 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.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();
    }
}

Related

  1. convertToXml(Object obj)
  2. convertToXml(Object obj, String encoding)
  3. createXML(Object o)
  4. getObjects(List> objEls)
  5. getObjects(List objEls)
  6. getXMLString(Object person, Class clazz)
  7. getXmlString(T jaxbObject)
  8. Object2Xml(Object object)
  9. objectToXML(Class cls, Object entity)