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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:18:19+00:00 2026-05-15T12:18:19+00:00

I have an existing data model. I would like to express this data model

  • 0

I have an existing data model. I would like to express this data model in terms of XML.

It looks like I have two options if I’m to use JAXB:

  • Create an XSD that mirrors my data model, and use xjc to create binding objects. Marshalling and unmarshalling will involve creating a “mapping” class that would take my existing data objects and map them to the objects that xjc created. For example, in my data model I have a Doc class, and JAXB would create another Doc class with basically the same exact fields, and I would have to map from my Doc class to xjc’s Doc class.
  • Annotate my existing data model with JAXB annotations, and use schemagen to generate an XSD from my annotated classes.

I can see advantanges and disadvantages of both approaches. It seems that most people using JAXB start with the XSD file. It makes sense that the XSD should be the gold standard truth, since it expresses the data model in a truly cross-platform way.

I’m inclined to start with the XSD first, but it seems icky that I have to write and maintain a separate mapping class that shuttles data in between my world and JAXB world.

Any recommendations?

  • 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-15T12:18:20+00:00Added an answer on May 15, 2026 at 12:18 pm

    Having the XSD generated from the existing classes sounds to me like the safest way to go.

    However methinks that unless you know JAXB well then the approach with annotating your own classes may turn out to be extremely frustrating (in both pain and time :)).

    This has happened to me in a related context when I tried to manually extract superclass from JAXB generated classes and then marshal the instances to XML. I was getting various (cryptic) JAXB exceptions. True, my JAXB knowledge is not that deep yet.

    If you insist on using JAXB then I suggest to consider using the first approach (XSD + XJC) as a way to obtain initial JAXB annotations for your classes.

    You can use XSD + XJC to get an idea how to annotate your own classes. Then you can try and fit the correct annotations onto them. Start with the more complex classes (references, inheritance, list of references, list of references to abstract base class) early on.

    Using another technology to generate XSD from non-annotated classes as a kick start on the XSD may help. Or you may go for an XSD that covers most of what your classes use.

    If the intention of this effort is to be also able to marshal the instances into XML, then I suggest to be on watch for JAXBElement. In some cases (which I cannot pin point due to lack of knowledge) instances will not marshal unless they are wrapped in a JAXBElement.

    We use HyperJAXB to generate persistence tier based on a set of XSDs. The generated classes are also used for marshaling. We have plenty of ‘fun’ making this to work esp. because of IDREFs and JAXBElement.

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

Sidebar

Ask A Question

Stats

  • Questions 483k
  • Answers 483k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've reduced verify.c (in openssl/apps/) to the minimum functions required.… May 16, 2026 at 6:58 am
  • Editorial Team
    Editorial Team added an answer Note that delegates are reference types, and their default value… May 16, 2026 at 6:58 am
  • Editorial Team
    Editorial Team added an answer If you are asking how a UIView subclass can draw… May 16, 2026 at 6:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.