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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:30:25+00:00 2026-06-09T15:30:25+00:00

Here is the XSD schema that i created for a WS <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault=qualified

  • 0

Here is the XSD schema that i created for a WS

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="shipmentStatus" type="shipmentStatusType" />

<xs:complexType name="shipmentStatusType">
    <xs:sequence>
        <xs:element name="orderNumber" type="xs:int"/>
    </xs:sequence>

    <xs:attribute name="requestStatus">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="SHIPPED"/>
                <xs:enumeration value="PENDING"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:attribute>

</xs:complexType>

When i generated Java classes using JAXB 2.1, it generated only one class i.e. shipmentStatusType. I was expecting that it will generate requestStatus as a JAVA Enum but it didn’t. Is it an expected behaviour or did i miss something?

  • 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-09T15:30:27+00:00Added an answer on June 9, 2026 at 3:30 pm

    Just extract your enum/simple type declaration to top-level one and use it as type of the XML attribute:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="http://www.example.com" xmlns="http://www.example.com"
        xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
        attributeFormDefault="unqualified">
    
        <xs:simpleType name="requestStatus">
            <xs:restriction base="xs:string">
                <xs:enumeration value="SHIPPED" />
                <xs:enumeration value="PENDING" />
            </xs:restriction>
        </xs:simpleType>
    
        <xs:complexType name="shipmentStatus">
            <xs:sequence>
                <xs:element name="orderNumber" type="xs:int" />
            </xs:sequence>
            <xs:attribute name="requestStatus" type="requestStatus" />
        </xs:complexType>
    
        <xs:element name="shipmentStatus" type="shipmentStatus" />
    
    </xs:schema>
    

    It will give you such an enum:

    /**
     * <p>Java class for requestStatus.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * <p>
     * <pre>
     * &lt;simpleType name="requestStatus">
     *   &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
     *     &lt;enumeration value="SHIPPED"/>
     *     &lt;enumeration value="PENDING"/>
     *   &lt;/restriction>
     * &lt;/simpleType>
     * </pre>
     * 
     */
    @XmlType(name = "requestStatus")
    @XmlEnum
    public enum RequestStatus {
    
        SHIPPED,
        PENDING;
    
        public String value() {
            return name();
        }
    
        public static RequestStatus fromValue(String v) {
            return valueOf(v);
        }
    
    }
    

    and class having it:

    /**
     * <p>Java class for shipmentStatus complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType name="shipmentStatus">
     *   &lt;complexContent>
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
     *       &lt;sequence>
     *         &lt;element name="orderNumber" type="{http://www.w3.org/2001/XMLSchema}int"/>
     *       &lt;/sequence>
     *       &lt;attribute name="requestStatus" type="{http://www.example.com}requestStatus" />
     *     &lt;/restriction>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "shipmentStatus", propOrder = {
        "orderNumber"
    })
    public class ShipmentStatus {
    
        protected int orderNumber;
        @XmlAttribute(name = "requestStatus")
        protected RequestStatus requestStatus;
    
        /**
         * Gets the value of the orderNumber property.
         * 
         */
        public int getOrderNumber() {
            return orderNumber;
        }
    
        /**
         * Sets the value of the orderNumber property.
         * 
         */
        public void setOrderNumber(int value) {
            this.orderNumber = value;
        }
    
        /**
         * Gets the value of the requestStatus property.
         * 
         * @return
         *     possible object is
         *     {@link RequestStatus }
         *     
         */
        public RequestStatus getRequestStatus() {
            return requestStatus;
        }
    
        /**
         * Sets the value of the requestStatus property.
         * 
         * @param value
         *     allowed object is
         *     {@link RequestStatus }
         *     
         */
        public void setRequestStatus(RequestStatus value) {
            this.requestStatus = value;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mvc.SiteMap defined something like this: <mvcSiteMap xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns=http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 xsi:schemaLocation=http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 MvcSiteMapSchema.xsd enableLocalization=true
I have xsd schema file which I can't change. Here is an excerpt that
Here is a schema file, midi.xsd that defines a type, note , used to
So here's the scenario...I have an XSD file describing all the objects that I
I have an xml and xsd file that both validate correctly (tested at http://xsdvalidation.utilities-online.info/
Here is my first attempt at validating XML with XSD. The XML file to
Here is the situation. I have received a WSDL (and included XSD) from someone
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
I created a WCF Webservice method that receives two parameters, string, and return an
I am working on a C# application that involves using XML schema file as

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.