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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:42+00:00 2026-05-24T21:35:42+00:00

For a uni assignment I’m writing a java program which needs to save and

  • 0

For a uni assignment I’m writing a java program which needs to save and load an object hierarchy to XML files. For example, the program creates a Zoo class with a list of subclasses of Animals, saves this to XML, and is loaded again the next time the user starts the program.

The file might look like

<Zoo>
    <Animals>
        <Lion>
            <name>Leo</name>
            <age>5</age>
            <roar>fearsome</roar>
        </Lion>
        <Elephant>
            <name>Dumbo</name>
            <age>10</age>
            <ears>let him fly</ears>
        </Elephant>
    </Animals>
</Zoo>

There is a low, finite number of subclasses of Animal I need to support (~5). Each subclass of animal has individual attributes (like Ears and Roar). I’m confused as to what the best design pattern for object creation and file creation is.

Currently, I have a class, XMLCreator, with methods such as void createZooElement(Zoo), void createLionElement(Lion) etc etc, and an XMLReader class with private Zoo createZoo(File), private Lion createLionObject(Element).

Is this a good way to go if this were code you expect to be maintained by others in the future? Or should each object have a constructor method which takes a File/Element as a parameter and another method which returns a File/XMLElement? Which is the way with the most encapsulation/maintainability?

  • 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-24T21:35:42+00:00Added an answer on May 24, 2026 at 9:35 pm

    I would just use JAXB, which allows marshalling a tree of objects (of annotated classes) to XML, and unmarshalling XML to a tree of objects. There are other Object to XML APIs, but JAXB comes with Java SE and works well.

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

Sidebar

Related Questions

In a simple RMI game I'm writing (an assignment in uni), I reveice: java.rmi.MarshalException:
I have to program a simple threaded program with MFC/C++ for a uni assignment.
The assignment at my first year uni computing course says my program should read
I'm doing a project at uni and would like to create zip files which
I am working on a uni assignment, which is to be done in C.
This is a very basic program for Uni which writes user data to a
This is uni assignment and I have already done some stuff. Please go to
This is a question corresponds to my uni assignment so I am very sorry
Since uni, I've programming in Java for 3 years, although I am not fully
As an exercise for my Java course in Uni this morning, I had to

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.