Java XML QName marshalToString(T obj, Class clazz, QName qname)

Here you can find the source of marshalToString(T obj, Class clazz, QName qname)

Description

marshal To String

License

Apache License

Declaration

public static <T> String marshalToString(T obj, Class<T> clazz, QName qname)
            throws javax.xml.bind.JAXBException, java.io.IOException 

Method Source Code


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

import javax.xml.bind.JAXBElement;

import javax.xml.namespace.QName;

public class Main {
    public static <T> String marshalToString(T obj, Class<T> clazz, QName qname)
            throws javax.xml.bind.JAXBException, java.io.IOException {

        java.io.StringWriter sw = new java.io.StringWriter();
        javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(clazz.getPackage().getName());
        javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(new JAXBElement(qname, clazz, obj), sw);
        sw.close();//from   w  w w  .ja v a 2 s. c om
        return sw.toString();

    }
}

Related

  1. isType(Map> types, QName name, QName attributeName)
  2. isValidQName(String localPart)
  3. isWildcardType(QName type)
  4. marshal(T value, Class elementClass, String packageName, QName q_name, OutputStream oStream)
  5. marshallJAXBElement(Class declaredType, QName name, Class scope, BoundType v)
  6. match(XMLStreamReader reader, QName name)
  7. matches(Node node, String requiredLocalName, QName requiredNamespace)
  8. matches(QName qname, Node node)
  9. matchingNamespace(Node node, QName requiredNamespace)