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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:09:01+00:00 2026-06-12T12:09:01+00:00

I am developing a game, I would like to save the state of the

  • 0

I am developing a game, I would like to save the state of the objects in xml file. I don’t have a schema for it. Say I have, Country has list of States objects and that has a list of cities objects. How can I generate an xml schema that saves their information?

  • 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-12T12:09:02+00:00Added an answer on June 12, 2026 at 12:09 pm

    See below example helps you,

    1. Main Class
      public class CreateXML {

      public static void main(String[] args) {
          try {
              final JAXBContext context = JAXBContext.newInstance(Country.class);
              final Marshaller marshaller = context.createMarshaller();
              // Create a stringWriter to hold the XML
              final StringWriter stringWriter = new StringWriter();
              CreateXML xml = new CreateXML();
              Country country = xml.createCountry();
              marshaller.marshal(country, stringWriter);
              // Print out the contents of the stringWriter
              System.out.println(stringWriter.toString());
          } catch (JAXBException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
      private List<String> createCity(){
          List<String> cities = new ArrayList<String>();
          cities.add("Slough");
          cities.add("Manchestor");
          return cities;
      }
      private List<State> createState(){
          List<State> states = new ArrayList<State>();
          State state = new State();
          state.setStatName("London");
          state.setCityList(createCity());
          states.add(state);
          return states;
      }
      private Country createCountry(){
          Country country = new Country("UK", createState());
          return country;
      }
      

      }

    2.Java Beans – Country

    @XmlRootElement
    public class Country {
    
        String countryName;
        List<State> states;
        public Country(String countryName, List<State> states) {
            this.countryName = countryName;
            this.states = states;
        }
        public Country() {
        }
        public String getCountryName() {
            return countryName;
        }
        public void setCountryName(String countryName) {
            this.countryName = countryName;
        }
        public List<State> getStates() {
            return states;
        }
        public void setStates(List<State> states) {
            this.states = states;
        }
    
    }
    

    3.Javabean State

    String statName;
    List<String> cityList;
    
    public State() {
    }
    public String getStatName() {
        return statName;
    }
    public void setStatName(String statName) {
        this.statName = statName;
    }
    public List<String> getCityList() {
        return cityList;
    }
    public void setCityList(List<String> cityList) {
        this.cityList = cityList;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a PHP game and would like to post players highscores to their
I am developing a computer baseball game based on statistics. I would like to
I am developing a multiplayer game with more than 2 players. I would like
I'm developing a board game and would like to know how i can use
I am developing a game, and I would like to transition between several views,
While developing a game I have designed a class that in normal operation has
I am developing a 3D Game Engine as a project. I would like to
I'm developing a card playing game and would like to print out the symbol
I am developing a 3d shooter game that I would like to run on
We are developing an iPhone game and I would like to know if is

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.