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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:36:29+00:00 2026-05-28T16:36:29+00:00

How can I generate XML with the following schema using JAXB. <NS1:getRatesResponse xmlns:NS1="http://mynamespaceTypes"> <response>

  • 0

How can I generate XML with the following schema using JAXB.

<NS1:getRatesResponse xmlns:NS1="http://mynamespaceTypes">
    <response>
        <NS2:rates xmlns:NS2="http://mynamespace">
            <currency>USD</currency>

        </NS2:rates>
        <NS3:rates xmlns:NS3="http://mynamespace">
            <currency>EUR</currency>
            
        </NS3:rates>
        <NS4:rates xmlns:NS4="http://mynamespace">
           ... etc
    </response>
</NS1:getRatesResponse>

I don’t know how to tell JAXB that every new item should be NS(n+1) with the same namespace. Changing XML format is not an option, because it’s external.

JAXB parses this XML correctly, but when producing using same classes it produces it like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:getRatesResponse
   xmlns:ns2="http://mynamespaceTypes" 
   xmlns:ns3="http://mynamespace">
  <response>
    <ns2:rates>
     <currency>EUR</currency>
     
    </ns2:rates>
    <ns2:rates>
     <currency>USD</currency>
     
    </ns2:rates>
  </response>
 </ns3:getRatesResponse>
  • 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-28T16:36:30+00:00Added an answer on May 28, 2026 at 4:36 pm

    For this use case I would do the following:

    1. Create a StAX XMLStreamWriter
    2. Write the getRatesResponse and response elements directly to the XMLStreamWriter
    3. Set the following property on marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); to prevent the header from being written on each marshal call.
    4. Marshal each of the Rate objects to the XMLStreamWriter individually.
    5. On the Marshaller set an instance of NamespacePrefixMapper on it to control the namespace prefix (this currently requires the JAXB RI, support for this extension is currently being added to EclipseLink JAXB (MOXy)).

    For More Information

    • http://blog.bdoughan.com/2011/11/jaxb-and-namespace-prefixes.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an XSD which can generate the following XML. <note> <email:to>abc@def.com</email:to>
I am using xjc to generate Java classes from the XML schema and the
I'm using jaxb to generate java object class from xml schemas within an Ant
Please have a look at the following XML layout <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=match_parent android:layout_height=match_parent
This may be a beginner xml question, but how can I generate an xml
can anyone tell me how to generate form dynamically in Dotnet from xml file.
I can generate my models and schema.yml file based on an existing database. But
ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink() , @Html.BeginForm()
I know you can generate all permutations from a list, using glob or Algorithm::Permute
We are using JAXB for Java-xml binding.We initially created domain class and then using

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.