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 8721669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:15:30+00:00 2026-06-13T07:15:30+00:00

We are using JAXB for Java-xml binding.We initially created domain class and then using

  • 0

We are using JAXB for Java-xml binding.We initially created domain class and then using schemagen commandline tool the following schema has been generated. But generated schema is not valid, giving following error message.

Error Message:
cos-all-limited.1.2: An all model group must appear in a particle with {min occurs} = {max occurs} = 1, and that particle must be part of a pair which constitutes the {content type} of a complex type definition.

Use Case:
There are two classes Emp(Base class) and Dept(Child class).
1. There is no restriction on the elements sequence(means empId, deptId and deptName can appear in any order). so we used xs:all element
2. In Dept class, deptId field should appear only once(minOccurs =1, maxOccurs=1) and deptName is optional.
As per my usecase i am unable to generate valid schema. I did search on google. But i couldn’t find the solution. So i am anticipating experts can answer this query. Could you please look into below classes,schema and guide me in the right direction.

NOTE: please don’t suggest me to create some temporary domain classes.
Thanks in anticipation.

Emp.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="EmpType", propOrder={})
@XmlRootElement
public class Emp {

    @XmlElement(name="empId", required = true)
    private String empId;
}

Dept.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="DeptType", propOrder={})
public class Dept extends Emp
{

    @XmlElement(name="deptId", required = true)
    private String deptId;
    private String deptName;
}

Schema1.xsd

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="emp" type="EmpType"/>

  <xs:complexType name="EmpType">
    <xs:sequence>
      <xs:element name="empId" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="DeptType">
    <xs:complexContent>
      <xs:extension base="EmpType">
        <xs:all>  <!--showing error message, mentioned above -->
          <xs:element name="deptId" type="xs:string" minOccurs="1" maxOccurs="1"/>
          <xs:element name="deptName" type="xs:string" minOccurs="0"/>
        </xs:all>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>
  • 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-13T07:15:31+00:00Added an answer on June 13, 2026 at 7:15 am

    The document structure that you are trying to allow is actually difficult to represent in an XML schema. You may not be able to generate it from a JAXB (JSR-222) annotated model. You do however have a couple of options:

    Option #1 – Generate a Simpler XML Schema

    If you are not validating XML content with your XML schema and are simply using it as documentation that people can use as a guide then I would drop the all sections and use sequence instead. This will work better with the inheritance relationship that you have. If you don’t specify an instance of Schema on the Unmarshaller the order of elements is not enforced so you will be able to read all the XML documents that meet your rules.

    Option #2 – Create Your Own XML Schema

    If you want the XML schema to exactly reflect all the possible accepted inputs then you will need to write it yourself. You can reference this existing XML schema by using the package level @XmlSchema annotation.

    @XmlSchema(location = "http://www.example.com/package/YourSchema.xsd")
    package com.example;
    
    import javax.xml.bind.annotation.XmlSchema;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to create a JAXB java class out of a xml schema using a
I'm using jaxb to generate java object class from xml schemas within an Ant
I have this schema and i'm using JAXB to generate java stub files. <?xml
I am trying to generate xml using jaxb. I created xsd and generated java
I got error while binding the xml schema int Java Object by using the
What are you using for binding XML to Java? JAXB, Castor, and XMLBeans are
Using JAXB in Java it is easy to generate from a xml schema file
I wamt to generate xml from java class using JAXB from a bean class,please
I am trying to create java objects from xml file. I am using jaxb(unmarshalling)
I want to unmarshall the following XML structure using JAXB: <orCondition> <andCondition> <andCondition> <simpleCondition

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.