Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have tried to reproduce your problem, but here it's working correctly: When marshalling the spam element does get a ns2 namespace.</p> <p>My marshalling code:</p> <pre><code> Bar bar = new Bar(); bar.setSpam("s"); MyDoc myDoc = new MyDoc(); myDoc.setBar(bar); JAXBContext context = JAXBContext.newInstance("org.mydoc"); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(myDoc, System.out); </code></pre> <p>Output:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;&lt;myDoc xmlns="http://www.mydoc.org" xmlns:ns2="http://www.mytypes.com"&gt;&lt;ns2:bar&gt;&lt;ns2:spam&gt;s&lt;/ns2:spam&gt;&lt;/ns2:bar&gt;&lt;/myDoc&gt; </code></pre> <p>My JAXB version:</p> <pre><code>xjc version "JAXB 2.1.3 in JDK 1.6" JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build IBM JAXB 2.1.3 in JDK 1.6) </code></pre> <p><strong>EDIT:</strong></p> <p>The Bar.java class does have the following annotation:</p> <pre><code>@XmlElement(required = true) protected String spam; </code></pre> <p>The XmlElement also has a namespace attribute. Javadoc: <a href="http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElement.html#namespace()" rel="nofollow noreferrer">http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElement.html#namespace()</a></p> <p>By default it will look at the @XmlSchema annotation in the com.mytypes package. Did you remove the @XmlSchema annotation and/or the package-info.java file?</p>
 

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