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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:11:01+00:00 2026-06-07T17:11:01+00:00

I have a XSD file, from which I want to generate C# and Java

  • 0

I have a XSD file, from which I want to generate C# and Java classes as well.

I first set the namespace in the XSD according to my C# namespace where my classes resides. The generation (with the Microsoft tools) works fine and also the serialisation works great and I can validat them against the XSD – perfect.

Now I want to create java classes with JAXB.
The problem is that the classes which are going to be created have a different package structure then the one in C#. So when I set the XSD namespace to the package structure of java, it works fine. I can serialize and validate the XML.

Now my question(s):
Is there a way to solve this? (Have one XSD for both generation tools)
Do I lack a understanding of what the namespace actually is needed for?

Thank you

Edit: Since it seems to be that there is a missunderstanding, I added an example

XSD: targetNamespace = “http://foo.bar/mySubNs/model”

  • C# Modelnamespace: com.foo.mySubNs.model (which fits the XSD namespace)
    all generated classes will have the same namespace provided though the MS codegen
  • Java Modelnamespace : com.foo.myOtherSubNs.model (which differs from the XSD namespace)
    the generated classes will have the “C# namespace”. As a result the classes will not compile.

If I would change the namespace during the code generation for java, I can compile the classes. So far so good. But I won’t be able to validate the generated XML by that java classes against the XSD, since the namespace differs.

To marshall my objects in Java, I use JAXB like this:

  ValidationEventCollector validationCollector = new ValidationEventCollector();
  SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema = schemaFactory.newSchema(new File ("my/schema/location"));

  // JAXB_CONTEXT is just an instance of "JAXBContext"
  Marshaller marshaller = JAXB_CONTEXT.createMarshaller();    

  marshaller.setSchema(schema);

  marshaller.setEventHandler(validationCollector);

  marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

  JAXBElement<MyClass> root = new JAXBElement<MyClass> (  new QName(MyClass.class.getPackage().getName(),"MyClass"),MyClass.class, node);

  marshaller.marshal(root, new File("output/Path/obj.xml"));

To build my java classes from the schema I use a xjc-task in an ant build script:

<xjc destdir="${dir.src.gen}" removeOldOutput="no" extension="true">
    <schema dir="${dir.schema}" includes="${file.schema}"/>
    <binding dir="${dir.schema}" includes="*.xjb"/>
    <produces dir="${dir.src.gen}" includes="**/*.java"/>
</xjc>
  • 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-07T17:11:02+00:00Added an answer on June 7, 2026 at 5:11 pm

    The XSD namespace doesn’t have to match the package structure, at least not in Java. When generating the classes using JAXB just provide the package you want to put the classes into.

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

Sidebar

Related Questions

I have this Maven task to generate Java classes from an XSD file using
I have xsd file. I want to generate my entity model from this schema
I have an XSD file which is used to generate some objects which are
I have a package which just includes and xsd file to generate (via JAXB)
I have an xsd file from which I am generating a C# class. In
I have a .xsd file which I use to generate code with the xsd.exe
I'm trying to generate Java service classes from a WSDL definition I have already
I have xsd schema file which I can't change. Here is an excerpt that
We have an XSD file along with some java src files. How can we
I want to write an XML file. I have created an XSD file named

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.