Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB Unmarshall error
    primarykey
    data
    text
    <p>I'm using JAXB on my project, but from time to time, I face some problems that I can't solve. I have setup my environment like this:</p> <p>Armor Class</p> <pre><code>package com.fortresswars.entity.component; @XmlType(name = "armor", namespace = "http://fortresswars.com") public class ArmorComponent extends AbstractComponent </code></pre> <p>package-info.java</p> <pre><code>@XmlSchema(xmlns = @XmlNs(namespaceURI = "http://fortresswars.com", prefix = "fw"), elementFormDefault = XmlNsForm.UNQUALIFIED, namespace = "http://fortresswars.com") package com.fortresswars.entity.component; </code></pre> <p>The generated schema header is almost correct:</p> <pre><code>&lt;xs:schema elementFormDefault="unqualified" version="1.0" targetNamespace="http://fortresswars.com" xmlns:fw="http://fortresswars.com" xmlns:tns="http://fortresswars.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; </code></pre> <p>The only thing I didn't like is that TNS prefix that JAXB puts there and I can't remove. I'm using an ant task (<code>com.sun.tools.jxc.SchemaGenTask</code>), and I remember reading somewhere that this was the problem.</p> <p>The rest of the generated scheme follows below. I'll show only the relevant part about armor:</p> <pre><code>&lt;xs:complexType name="armor"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="tns:abstractComponent"&gt; &lt;xs:sequence&gt; &lt;xs:element name="value" type="xs:short" minOccurs="0"/&gt; &lt;xs:element name="type" type="tns:armor-type" minOccurs="0"/&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; </code></pre> <p>And the element that is using the armor component:</p> <pre><code> &lt;xs:complexType name="character"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="tns:thing"&gt; &lt;xs:sequence&gt; &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt; &lt;xs:element name="armor" type="tns:armor"/&gt; &lt;xs:element name="model" type="tns:model"/&gt; &lt;xs:element name="status" type="tns:status"/&gt; &lt;xs:element name="costs" type="tns:costs"/&gt; &lt;/xs:choice&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; </code></pre> <p>To test this, I created a XML Document (see the TNS prefix, I need to put it, or the <code>fw</code> prefix, along with the xmlns:fw also).</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;tns:character xmlns:tns="http://fortresswars.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="/home/shirkit/jMonkeyProjects/Fortress Wars/Core/schema/full.xsd"&gt; &lt;armor&gt; &lt;value&gt;5&lt;/value&gt; &lt;type&gt;NORMAL&lt;/type&gt; &lt;/armor&gt; &lt;/tns:character&gt; </code></pre> <p>But when I'm unmarshalling this document, here's the error I get:</p> <pre><code>Exception: unexpected element (uri:"", local:"armor"). Expected elements are &lt;{http://fortresswars.com}armor&gt;,&lt;{http://fortresswars.com}attacks&gt;,&lt;{http://fortresswars.com}costs&gt;,&lt;{http://fortresswars.com}model&gt;,&lt;{http://fortresswars.com}abilities&gt;,&lt;{http://fortresswars.com}status&gt;,&lt;{http://fortresswars.com}movement&gt; </code></pre> <p>I have setup elementFormDefault to UNQUALIFIED, and even though this doesn't work. Why I'm getting this exception? And can I remove TNS prefix from the generated schema?</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.
    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