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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:42:07+00:00 2026-06-08T19:42:07+00:00

trying to map my class to xml and add custom attributes. public class MyXmlMappings

  • 0

trying to map my class to xml and add custom attributes.

public class MyXmlMappings  {
    @XmlElement
    protected String username;
    @XmlElement
    protected String password;
    @XmlElement
    protected Integer age;
}

after marshalling to xml looks like something like this:

<myXmlMappings>
<username/>
<password/>
<age/>
</myXmlMappings>

I need to have xml like this:

<myXmlMappings>
<username type="String" defaultValue="hello" />
<password type="String" defaultValue="asdf" />
<age type="Integer" defaultValue="25" />
</myXmlMappings>

As you can see I added type and defaultValue attributes. How can I add them to myXmlMappings class to be visible after marshalling?

Adding extra fields to myXmlMappings class is not viable I would like to do it somehow with 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-06-08T19:42:10+00:00Added an answer on June 8, 2026 at 7:42 pm

    XML Representation

    I would recommend the following XML representation:

    <myXmlMappings>
        <xmlMapping name="username" type="String" defaultValue="hello" />
        <xmlMapping name="password" type="String" defaultValue="asdf" />
        <xmlMapping name="age" type="Integer" defaultValue="25" />
    </myXmlMappings>
    

    Java Model

    With the following Java model:

    XmlMappings

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class MyXmlMappings  {
        @XmlElement(name="xmlMapping")
        protected List<XmlMapping> xmlMappings;
    
    }
    

    XmlMapping

    @XmlAccessorType(XmlAccessType.FIELD)
    public class XmlMapping {
        @XmlAttribute
        protected String name;
        @XmlAttribute
        protected String type;
        @XmlAttribute
        protected String defaultValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I'm trying to implement an identity map using generics. I have an abstract class,
Hi I'm trying to map a one-many parent-child relationship in NHibernate using XML mapping.
I'm trying to add a composite primary key to a class and having a
I am trying to create a google map with custom icon markers. I need
I am currently trying to map my Java class hierarchy into my database using
I am trying to map a java model into some XML. To do this
I was trying to add the XML schema to an existing EJB project. JAXB
I'm trying to create a simple map in androi (I want to add GPS
I am trying to map the below interface using Moxy's XML Metadata extension. But

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.