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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:22:27+00:00 2026-05-15T17:22:27+00:00

I want to achieve the following xml using simple xml framework ( http://simple.sourceforge.net/ ):

  • 0

I want to achieve the following xml using simple xml framework (http://simple.sourceforge.net/):

<events>
    <course-added date="01/01/2010">
        ...
    </course-added>
    <course-removed date="01/02/2010">
        ....
    </course-removed>
    <student-enrolled date="01/02/2010">
        ...
    </student-enrolled>
</events>

I have the following (but it doesn’t achieve the desired xml):

@Root(name="events")
class XMLEvents {

    @ElementList(inline=true)
    ArrayList<XMLEvent> events = Lists.newArrayList();

        ...
}


abstract class XMLEvent {

    @Attribute(name="date")
    String dateOfEventFormatted;

    ...

}

And different type of XMLNodes that have different information (but are all different types of events)

@Root(name="course-added")
class XMLCourseAdded extends XMLEvent{

    @Element(name="course") 
    XMLCourseLongFormat course;

    ....
}

@Root(name="course-removed")
class XMLCourseRemoved extends XMLEvent {

    @Element(name="course-id")
    String courseId;

        ...

}

How should I do the mapping or what should I change in order to be able to achieve de desired xml?

Thanks!

  • 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-15T17:22:28+00:00Added an answer on May 15, 2026 at 5:22 pm

    A very clean way to solve the problem is to create your own converter such as:

    public class XMLEventsConverter implements Converter<XMLEvents> {
    
        private Serializer serializer;
    
        XMLEventsConverter(Serializer serializer){
            this.serializer = serializer;
        }
    
        @Override
        public XMLEvents read(InputNode arg0) throws Exception {
            return null;
        }
    
        @Override
        public void write(OutputNode node, XMLEvents xmlEvents) throws Exception {
            for (XMLEvent event : xmlEvents.events) {
                serializer.write(event, node);
            }
        }
    
    }
    

    And then use a RegistryStrategy and bind the class XMLEvents with the previous converter:

    private final Registry registry = new Registry();
    private final Serializer serializer = new Persister(new RegistryStrategy(registry));
    ....
    registry.bind(XMLEvents.class, new XMLEventsConverter(serializer));
    

    In this way the xml obtained is the one desired. Note that the read method on the XMLEventsConverter just return null, in case you need to rebuild the object from the xml file you should properly implement it.

    Regards!

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

Sidebar

Related Questions

The following code is almost the same thing I want to achieve. <?xml version=1.0
I want to achieve something like the following: UrlBuilder ub = new UrlBuilder(http://www.google.com/search); ub.Parameters.Add(q,request);
I want to be able to achieve the following using guice/gin: Get all sort
I want to achieve XML in this style using C# XMLseralizer <state id=s1>val<state />
I am a VB.NET beginner. I want to achieve following: Node1 is clicked which
I want to achieve the following hierarchical navigation model in a WPF MVVM application:
I have a gridview with couple of columns,I want to achieve the following: If
I would like to achieve the following: I want a free Application Lifecycle Management
Is there a way to achieve the following in Maven? I want to exclude
I want to use a scripting language(Javascript, PHP) to achieve the following task. 1)I

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.