Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:02:42+00:00 2026-06-02T20:02:42+00:00

I’m using JAXB to generate a XML Schema from my Java classes so the

  • 0

I’m using JAXB to generate a XML Schema from my Java classes so the other developers can create instances of the classes easily without knowledge in Java.

Here’s the relevant part of the code:

package-info.java

@XmlSchema(xmlns = @XmlNs(prefix = "p", namespaceURI = "http://mygame.com"),
           namespace = "http://mygame.com")

package com.mygame.entity.properties;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;

Model.class

package com.mygame.entity.properties;

@XmlType(name = "model", namespace = "http://mygame.com")
@XmlRootElement(name = "model", namespace = "http://mygame.com")
public class Model {

    @XmlAttribute(required = true)
    public String path;

    public Model() {
    }
}

Unit.class

@XmlType(name="unit", namespace="http://mygame.com")
@XmlRootElement(name="unit", namespace="http://mygame.com")
public class Unit extends GameObject {
}

GameObject.class

@XmlType(name = "gameobject", namespace = "http://mygame.com")
public abstract class GameObject extends Thing {

    // Attributes
    public Armor armor;
    public Short maxHp;
    public Boolean walkable = false;
    public AbstractModel model;
}

Thing.class

@XmlType(name="thing", namespace="http://mygame.com")
public abstract class Thing {
    // Constants
    // Attributes

    @XmlElement(required=false)
    public String icon;
}

Generated XML Schema

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://mygame.com" xmlns:e="http://mygame.com" xmlns:s="http://mygame.com" xmlns:tns="http://mygame.com" xmlns:p="http://mygame.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">


  <xs:element name="model" type="tns:model"/>

  <xs:element name="unit" type="tns:unit"/>

  <xs:complexType name="thing" abstract="true">
    <xs:sequence>
      <xs:element name="icon" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="unit">
    <xs:complexContent>
      <xs:extension base="tns:gameobject">
        <xs:sequence/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="gameobject" abstract="true">
    <xs:complexContent>
      <xs:extension base="tns:thing">
        <xs:sequence>
          <xs:element ref="tns:armor" minOccurs="0"/>
          <xs:element name="maxHp" type="xs:short" minOccurs="0"/>
          <xs:element name="walkable" type="xs:boolean" minOccurs="0"/>
          <xs:element ref="tns:model" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="model">
    <xs:sequence/>
    <xs:attribute name="path" type="xs:string" use="required"/>
  </xs:complexType>


</xs:schema>

Up to this point, everything is fine. It generates correctly a wanted XML (althought with those annoying TNS prefix, but that’s fine).

The problem is when I try to unmarshall a UNIT, I’m getting an error in one of the cases

Case 1 – Working

Given this XML input, everything works fine and I get a instance of my class correctly.

<?xml version="1.0" encoding="UTF-8"?><tns:unit xmlns:tns="http://mygame.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="/home/shirkit/jMonkeyProjects/Fortress Wars/Core/schema/full.xsd">
<maxHp>100</maxHp>
<walkable>false</walkable>
<model path="Models/Oto/Oto.mesh.xml"/></tns:unit>

Case 2 – Not working

Given this, I get an error described below

<?xml version="1.0" encoding="UTF-8"?><tns:unit xmlns:tns="http://mygame.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="/home/shirkit/jMonkeyProjects/Fortress Wars/Core/schema/full.xsd">
<maxHp>100</maxHp>
<walkable>false</walkable>
<tns:model path="Models/Oto/Oto.mesh.xml"/></tns:unit>


unexpected element (uri:"http://mygame.com", local:"model"). Expected elements are <{}icon>,<{}model>,<{}walkable>,<{}armor>,<{}maxHp>

The only difference between the two XML input is that one has the element model, and the other has the element tns:model. I don’t know why I’m getting this error in the Case 2, can someone give me an explanation for that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:02:45+00:00Added an answer on June 2, 2026 at 8:02 pm

    you either need to drop the tns prefix from the model element or specify in your schema the “elementFormDefault” value of QUALIFIED (personally, i prefer this solution).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.