Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB: How to avoid repeated namespace definition for xmlns:xsi
    primarykey
    data
    text
    <p>I have a JAXB setup where I use a @XmlJavaTypeAdapter to replace objects of type <code>Person</code> with objects of type <code>PersonRef</code> that only contains the person's UUID. This works perfectly fine. However, the generated XML redeclares the same namespace (<code>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</code>) every time it's used. While this is generally okay, it just doesn't feel right.</p> <p>How can I configure JAXB to declare xmlns:xsi at the very beginning of the document? Can I manually add namespace declarations to the root element?</p> <p>Here's an example of what I want to achive:</p> <p><strong>Current:</strong></p> <pre><code>&lt;person uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a"&gt; &lt;relation type="CHILD"&gt; &lt;to xsi:type="personRef" uuid="56a930c0-5499-467f-8263-c2a9f9ecc5a0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt; &lt;/relation&gt; &lt;relation type="CHILD"&gt; &lt;to xsi:type="personRef" uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt; &lt;/relation&gt; &lt;!-- SNIP: some more relations --&gt; &lt;/person&gt; </code></pre> <p><strong>Wanted:</strong></p> <pre><code>&lt;person uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;relation type="CHILD"&gt; &lt;to xsi:type="personRef" uuid="56a930c0-5499-467f-8263-c2a9f9ecc5a0"/&gt; &lt;/relation&gt; &lt;relation type="CHILD"&gt; &lt;to xsi:type="personRef" uuid="6ec0cf24-e880-431b-ada0-a5835e2a565a"/&gt; &lt;/relation&gt; &lt;!-- SNIP: some more relations --&gt; &lt;/person&gt; </code></pre>
    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.
    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