Note that there are some explanatory texts on larger screens.

plurals
  1. POAltering the XML header produced by the JAXB marshaller
    primarykey
    data
    text
    <p>I am currently using the following code to marshal an object into an xml string</p> <pre><code> JAXBContext context; try { context = JAXBContext.newInstance(heartbeat.getClass()); StringWriter writer = new StringWriter(); Marshaller marshaller = context.createMarshaller(); heartbeat.setHeader(header); heartbeat.setHeartbeatEvent(event); marshaller.marshal(heartbeat, writer); String stringXML = writer.toString(); return stringXML; } catch (JAXBException e) { throw new RuntimeException("Problems generating XML in specified " + "encoding, underlying problem is " + e.getMessage(), e); } </code></pre> <p>Which produces the following header</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; </code></pre> <p>My desired output is the following</p> <pre><code>&lt;?xml version=\"1.0\"?&gt; </code></pre> <p>By adding this to the marshaller</p> <pre><code>marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "&lt;?xml version=\"1.0\"?&gt;"); </code></pre> <p>I receive</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;&lt;?xml version="1.0"?&gt; </code></pre> <p>and changing the JAXB_FRAGMENT property to TRUE removes the header entirely. I have been following the <a href="https://stackoverflow.com/questions/277996/jaxb-remove-standalone-yes-from-generated-xml">JAXB - Remove &#39;standalone=&quot;yes&quot;&#39; from generated XML</a> thread attempting to solve the problem but I have had no luck so far. Can someone please give me some insight on how to get my desired header from the JAXB marshaller?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload