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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:58+00:00 2026-06-17T12:33:58+00:00

I am using Jaxb to generate Java classes. My schema has the following element

  • 0

I am using Jaxb to generate Java classes. My schema has the following element defined:

<xs:complexType name="AutomobileType" abstract="true">
    <xs:sequence>
        <xs:element name="Color" type="core:ColorName"/>
        <xs:element name="Weight" type="core:PoundsWeightType"/>
        <xs:element name="Fuel" type="Fuel"/>
        <xs:element name="NumDoors" type="xs:nonNegativeInteger"/>
        <xs:element name="NumCylinders">
            <xs:simpleType>
                <xs:restriction base="xs:int">
                    <xs:minInclusive value="1"/>
                    <xs:maxInclusive value="12"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
    </xs:sequence>
</xs:complexType>    
<xs:element name="Automobile" type="AutomobileType"/>

As you can see, I have one element called Automobile.

Jaxb creates the classes and an ObjectFactory that I use to create instances of Automobile. The thing that baffles me is the method to create an instance of Automobile is as follows:

public JAXBElement<AutomobileType> createAutomobile(AutomobileType value)

Why does the createAutomobile method have an argument? How do I use this method?

I tried the following:

ObjectFactory objectFactory = new ObjectFactory();
objectFactory.createAutomobile(new Automobile());

but this does not compile because the Automobile class is abstract and therefore I cannot create an instance.

  • 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-17T12:33:58+00:00Added an answer on June 17, 2026 at 12:33 pm

    There is another method :

     public AutomobileType createAutomobileType();
    

    In JAXB, the xsd:complexType “AutomobileType” construct maps the class of the same name. It is meant to be the data structure that is equivalent to that XML schema type.

    The JAXBElement<> is a (parameterized) wrapper type that associates the java object and the element name and namespace, and that’s why its constructor takes an AutomobileType object as parameter in the constructor, in addition to the element namespace and the element name.
    The generated ObjectFactory “createAutomobile(..)” is just a convenience method to wrap that constructor, hard-coding your namespace and element name from your XML schema.

    While this dichotomy is not all straight forward at first, consider that you could have another element by another name

    They would be structurally equivalent, but the element name would be different. You would have another ObjectFactory method “createMotorcycle(…)”.

    You can create an un-named automobileType object for the purpose of building the contents of the xml element, and then tell JAXB exactly which XML element it should be represented as.

    I can’t recommend enough reading the JAXB documentation on the topic.

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

Sidebar

Related Questions

I'm want to generate java classes from a schema using jaxb, but I am
I'm using JAXB(xjc version 2.2.4-2) to generate Java classes from a XML Schema. The
I'm using JAXB to generate a XML Schema from my Java classes so the
I have this schema and i'm using JAXB to generate java stub files. <?xml
We are using JAXB to generate Java classes and have encountered a few cases
Using JAXB in Java it is easy to generate from a xml schema file
I want to generate Java classes from a dtd file using JAXB. The dtd
How can I generate XML with the following schema using JAXB. <NS1:getRatesResponse xmlns:NS1="http://mynamespaceTypes"> <response>
I'm using JAXB and XJC for first time. I would like to generate Java
I have an XML schema: <xsd:element name=Person> <xsd:complexType> <xsd:sequence> <xsd:element name=name type=xsd:string /> <xsd:element

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.