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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:48:30+00:00 2026-05-18T10:48:30+00:00

I am trying to generate xml using jaxb. I created xsd and generated java

  • 0

I am trying to generate xml using jaxb. I created xsd and generated java classes.
But when I generate xml, I am geeting prefix ns2 to the root tag, which I don’t want.

ex: I want root tag to be

 <report>
   <id>rep 1</id>
</report>

, But getting as

<ns2:report>
....
</ns2:report>

In the generated java class, I gave annotation as @XmlRootElement(name="report",namespace="urn:report")

Can some one pls help

  • 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-18T10:48:30+00:00Added an answer on May 18, 2026 at 10:48 am

    If this is your class:

    package example;
    
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement(name="report",namespace="urn:report")
    public class Root {
    
        private String id;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
    }
    

    Then it makes sense that there is a prefix on the root element, because you have specified that the “root” element is namespace qualified and the “id” element is not.

    <ns2:report xmlns:ns2="urn:report">
        <id>123</id>
    </ns2:report>
    

    If you add a package-info class to your model, you can leverate the @XmlSchema annotation:

    @XmlSchema(
            namespace = "urn:report",
            elementFormDefault = XmlNsForm.QUALIFIED)
    package example;
    
    import javax.xml.bind.annotation.XmlNsForm;
    import javax.xml.bind.annotation.XmlSchema;
    

    Then the JAXB implementation may choose to leverage the default namespace, but note now all of the elements are namespace qualified which may or may not match your XML schema:

    <report xmlns="urn:report">
        <id>123</id>
    </report>
    

    For more information on JAXB and namespaces see:

    • http://bdoughan.blogspot.com/2010/08/jaxb-namespaces.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
I'm trying to generate some XML using XML::Builder, but my element names need to
I am trying to generate a PDF using XSL(XML-FO) to transform a generated XML
I am trying to generate an XML document using the XML features in SQL
I'm trying to generate customized xml files from a template xml file in python.
I'm trying to generate a sitemap.xml on the fly for a particular asp.net website.
I'm trying to generate code coverage reports with EMMA using tests of which some
I am just trying to generate the classes for linq to mysql with dbmetal
I was trying to add the XML schema to an existing EJB project. JAXB
I'm trying to generate a XML document from the SQL Server 2005 database by

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.