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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:57:46+00:00 2026-05-13T00:57:46+00:00

I have object , tree/model/hierarchy, whatever the correct term is. It consists of what

  • 0

I have object, tree/model/hierarchy, whatever the correct term is. It consists of what could be characterized as a one-to-one mapping of the desired XML.

That is i have the following (in a non-standard UML sort of syntax)

class A {
    class B b[*]
    class C
    class D
}

class B {
    class C c[*]
    string AttributeFoo = "bar"
}

class C {
    string AttributeThis = "is"
}

class D {
    string AttributeName = "d"
}

Desired output is something like this:

<?xml version="1.0"?>
<a>
    <b attribute-foo="bar">
        <c attribute-this="is"/>
    </b>
    <c attribute-this="is"/>
    <d attribute-name="d"/>
</a>

What would you propose to be the best, and/or the simplest way of achieving this goal?

  • 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-13T00:57:46+00:00Added an answer on May 13, 2026 at 12:57 am

    I would look at JAXB because a) you get it in the standard library and b) it isn’t that complicated. This code requires Java 6:

    @XmlRootElement public static class A {
      public List<B> b = new ArrayList<B>();
    }
    
    public static class B {
      public List<C> c = new ArrayList<C>();
      @XmlAttribute(name = "attribute-foo") public String attributeFoo = "foo";
    }
    
    public static class C {
      @XmlAttribute(name = "attribute-this") public String attributeThis = "is";
    }
    
    public static void main(String[] args) {
      A a = new A();
      a.b.add(new B());
      a.b.get(0).c.add(new C());
      JAXB.marshal(a, System.out);
    }
    //TODO: getters/setters, error handling and so on
    

    Output:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <a>
        <b attribute-foo="foo">
            <c attribute-this="is"/>
        </b>
    </a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree that consists of several objects, where each object has a
I have an object tree that looks something like Ball / \ LegalBall IllegalBall
If I have a form-backing object that has a complicated object tree -- say
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have a set of tree objects with a depth somewhere in the 20s.
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have a large tree of Java Objects in my Desktop Application and am
I have object A which in turn has a property of type Object B
I have an object that is mapped to a cookie as a serialized base-64
I have an object graph serialized to xaml. A rough sample of what it

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.