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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:18:28+00:00 2026-05-14T04:18:28+00:00

I have an object config which has some properties. I can export this ok,

  • 0

I have an object config which has some properties. I can export this ok, however, it also has an ArrayList which relates to embedded classes which I can’t get to appear when I export to XML. Any pointers would be helpful.

Export Method

public String exportXML(config conf, String path) {
    String success = "";
    try {
        FileOutputStream fstream = new FileOutputStream(path);
        try {
            XMLEncoder ostream = new XMLEncoder(fstream);
            try {
                ostream.writeObject(conf);
                ostream.flush();
            } finally {
                ostream.close();
            }
        } finally {
            fstream.close();
        }
    } catch (Exception ex) {
        success = ex.getLocalizedMessage();
    }
    return success;
}

Config Class (some detail stripped to keep size down)

public class config {

protected String author = "";
protected String website = "";
private ArrayList questions = new ArrayList();

public config(){
}

public void addQuestion(String name) {
    questions.add(new question(questions.size(), name));
}

public void removeQuestion(int id) {
    questions.remove(id);
    for (int c = 0; c <= questions.size(); c++) {
        question q = (question) (questions.get(id));
        q.setId(c);
    }
    questions.trimToSize();
}

public config.question getQuestion(int id){
    return (question)questions.get(id);
}


/**
 * There can be multiple questions per config.
 * Questions store all the information regarding what questions are
 * asked of the user, including images, descriptions, and answers.
 */
public class question {

    protected int id;
    protected String title;
    protected ArrayList answers;

    public question(int id, String title) {
        this.id = id;
        this.title = title;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void addAnswer(String name) {
        answers.add(new answer(answers.size(), name));
    }

    public void removeAnswer(int id) {
        answers.remove(id);
        for (int c = 0; c <= answers.size(); c++) {
            answer a = (answer) (answers.get(id));
            a.setId(c);
        }
        answers.trimToSize();
    }

    public config.question.answer getAnswer(int id){
        return (answer)answers.get(id);
    }

    public class answer {

        protected int id;
        protected String title;

        public answer(int id, String title) {
            this.id = id;
            this.title = title;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }
    }
}

}

Resultant XML File

<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.6.0_18" class="java.beans.XMLDecoder"> 
 <object class="libConfig.config"> 
  <void property="appName"> 
   <string>xxx</string> 
  </void> 
  <void property="author"> 
   <string>Andy</string> 
  </void> 
  <void property="website"> 
   <string>www.example.com/dsx.xml</string> 
  </void> 
 </object> 
</java> 
  • 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-14T04:18:29+00:00Added an answer on May 14, 2026 at 4:18 am

    Xstream deals with this much better, from their description:

    • Requires no modifications to objects.
    • Serializes internal fields, including private and final.
    • Supports non-public and inner classes.
    • Classes are not required to have default constructor.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 354k
  • Answers 354k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to do this through VBScript and load in… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer EDIT: I tried to clarify I bit more ... 1.… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer Read each line, stick the contents of the line into… May 14, 2026 at 7:52 am

Related Questions

I recently added some namespaces to my web.config file so that all of my
I've created a small console application to see how quartz work and it was
Recently I was talking to a co-worker about C++ and lamented that there was
Dynamic libraries are nice. The have embedded information in them that help the runtime
I've been working on a .NET library. Of course .NET has a good way

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.