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

  • Home
  • SEARCH
  • 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 640277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:56:08+00:00 2026-05-13T20:56:08+00:00

If I have a simple class such as:- @XmlRootElement public class MyClass { @XmlAttribute(required=true)

  • 0

If I have a simple class such as:-

@XmlRootElement
public class MyClass
{
   @XmlAttribute(required=true)
   private String myattribute
}

Is it possible to validate a corresponding xml document WITHOUT an xml schema i.e. using only the annotations?

  • 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-13T20:56:09+00:00Added an answer on May 13, 2026 at 8:56 pm

    Good question. As far as I know, the required attribute is generated by XJC when it finds a non-optional schema type, and I think it’s also used by the schema generator. At runtime, though, it’s not used for anything, serving no other purpose than a documentary annotation.

    One thing you could consider is the JAXB runtime’s callback options. In this case, you could just define a afterUnmarshal() method on MyClass which programmatically validates the state of the object, throwing an exception if it doesn’t like it. See the above link for other options, including registering separate validator classes.

    Having said that, validation against a schema really is the best way. If you don’t have one, you should considering writing one. The schemagen tool can generate a schema from your object model, which you can then modify to add whatever constraints you like. Hopefully, schemagen will generate mandatory schema elements from your required=true class fields.

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

Sidebar

Related Questions

In VS 2010/.NET 4.0, I have a List<MyClass> list of a simple class as
I have a strange problem with the <ui:repeat> tag. Even for my very simple
I have no idea how to do this simple task. LightSwitch's Solution Explorer is
I have a few simple entities that are stored in a simple code table
I have written a JAXB mapping that stored a sublist inside a root element
I'd like to develope simple set of controls to display many sort of data
I would like to use factory classes and methods to generate GUI components, but
Im slowly delving into Silverlight and after a good while trying I am finally
First thing to note - I KNOW DELEGATION AND DECORATOR PATTERNS! Second - I
Please, consider the following (I'm sorry for the amount of code; but this is

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.