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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:46:50+00:00 2026-05-15T22:46:50+00:00

What I thought was going to be a simple problem turns out to be

  • 0

What I thought was going to be a simple problem turns out to be quite a head scratcher.

I am currently using JAXB 2 to generate code from an XSD on which I have no control. I need to access the constraints from the schemas so I can apply some logic and guard code when setting values in these objects. Validation in bulk simply will not do. In most cases I can simply truncate the string and all will be good. For this I need to get the length that was declared in the XSD in order to apply it in the guard code and keep this layer generic. The alternative is to copy and hard code the lengths but frankly if there was a better way to do this I would really appreciate.

I speak of string length here but this applies to all facets declarable in an XSD.

Suggestions, Code samples and links welcome, basically anything that would help me NOT hard code the data in the classes.

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-15T22:46:51+00:00Added an answer on May 15, 2026 at 10:46 pm

    I was faced with a similar problem and the best solution I found was to write my own XJC plugin. An XJC plugin has access to both the XML schema and the generated classes, so it seemed like the easiest way to get at the restriction information. My plugin added an annotation to any field in the generated class that had restrictions applied to it in the schema. For instance, an element like

    <xs:element name="text">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:maxLength value="20" />
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    

    would appear as

    @XmlRestrictions(maxLength = 20)
    protected String text;
    

    in the generated class file. Then, you could use reflection to extract the restriction information from the field.

    The documentation for creating a plugin isn’t too great, but I found this article useful. Take a look at the source code for the Default Value Plugin to see how to drill down into XJC’s in-memory representation of the XML schema and generated class structure. The JAXB, XSOM, and CodeModel API’s will also be helpful.

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

Sidebar

Related Questions

all, I started out with what i thought was going to be a pretty
I have a project that I thought was going to be relatively easy, but
I know this one is going to be a long-shot, but I thought I'd
I thought .Net code gets compiled into MSIL, so I always wondered how do
I thought I'd offer this softball to whomever would like to hit it out
Whats going on here? I thought SIGINT would be sent to the foreground process
I am sure this is something really simple, but I am going bonkers trying
So I've got a simple web application using Spring MVC + Hibernate and am
Setup Have you ever had the experience of going into a piece of code
I'm building a simple image gallery with jquery but running into an annoying problem.

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.