Obtener el resultado de Marshall en una cadena
JAXBContext context = JAXBContext
.newInstance(CreateExemptionCertificate.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(cc, System.out);
En el código anterior estoy obteniendo el resultado en la consola (quiero decir, XML se está imprimiendo en la consola). Quiero obtener este XML en una cadena. No estoy obteniendo qué argumento debería pasar al método marshal para obtener una cadena XML en una variable String en lugar de imprimirla en la consola. Cualquiera que tenga alguna idea por favor comparta.
29
Author: Sunny Gupta, 2012-02-05
3 answers
Puedes hacerlo así:
CreateExemptionCertificate cc = ...;
JAXBContext context = JAXBContext.newInstance(CreateExemptionCertificate.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter sw = new StringWriter();
m.marshal(cc, sw);
String result = sw.toString();
24
Author: Radouane ROUFID,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-21 15:12:07
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-21 15:12:07
Justo ahora tengo la respuesta a mi pregunta de este post a continuación:
Quiero convertir un flujo de salida en String object
Necesito usar StringWriter para tomar la cadena XML del método Marshal
22
Author: Sunny Gupta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:14
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:14
Trate de marshalling a una instancia de ByteArrayOutputStream
y luego invocando toByteArray
en ello.
5
Author: laz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-05 18:37:07
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-05 18:37:07