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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:18:01+00:00 2026-05-28T02:18:01+00:00

Hi I have just started learning about xsd as I want to use it

  • 0

Hi I have just started learning about xsd as I want to use it with JAXB.

I was wondering I may have an XML tag that started with the same element but could have completely different child elements every time.

Here is an example1:

    <service>Hotel
        <request>location
             <currentLongitude>100</currentLongitude>
             <currentLatitude>100</currentLatitude>
        </request>
    </service>

example2:

    <service>Hotel
        <request>Price
             <Single>130</Single>
             <Double>140</Double>
        </request>
    </service>

Basically how do I write this in xsd that “request” being asked can have completely different elements

Or if it is applicable is their a better way for me to process this xml then JAXB?

Thanks

  • 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-05-28T02:18:02+00:00Added an answer on May 28, 2026 at 2:18 am

    You can define your request element as:

    <xsd:element name="request">
        <xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    

    This will cause JAXB to generate a field/property that is annotated like:

    @XmlMixed
    @XmlAnyElement(lax = true)
    protected List<Object> content;
    

    FULL EXAMPLE

    any.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
        <xsd:element name="service">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element ref="request"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    
        <xsd:element name="request">
            <xsd:complexType mixed="true">
                <xsd:sequence>
                    <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    
    </xsd:schema>
    

    XJC Call

    xjc -d out -p forum8776746 any.xsd
    

    Service

    package forum8776746;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "request"
    })
    @XmlRootElement(name = "service")
    public class Service {
    
        @XmlElement(required = true)
        protected Request request;
    
        public Request getRequest() {
            return request;
        }
    
       public void setRequest(Request value) {
            this.request = value;
        }
    
    }
    

    Request

    package forum8776746;
    
    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAnyElement;
    import javax.xml.bind.annotation.XmlMixed;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    @XmlRootElement(name = "request")
    public class Request {
    
        @XmlMixed
        @XmlAnyElement(lax = true)
        protected List<Object> content;
    
        public List<Object> getContent() {
            if (content == null) {
                content = new ArrayList<Object>();
            }
            return this.content;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just recently have started learning about the wonders of **kwargs but I've hit
I have just started learning about Web Services. These are my understandings on a
I have just started learning java and i have about 8 months time. My
I just started learning about ASP.NET, and I have a couple of questions. Am
Very confused over this. I've just started learning about pointers and have now decided
I have just started learning about Java server faces and successfully tested out my
We just started learning about class inheritance and attribute lookup in python. I have
I have just started learning basics about Graphics2D class, So far I am able
I just started learning about database normalization and I have a question about one
I just started learning C++ and have a question about vectors. The book I'm

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.