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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:13:54+00:00 2026-06-05T04:13:54+00:00

I would like to convert data from a table to an XML file. The

  • 0

I would like to convert data from a table to an XML file. The data is in the following format

    Continent   Country     County      Town
    --------------------------------------------------------------
    Africa      Kenya       South       Mombasa
    Africa      Egypt       South       Cairo
    Europe      England     North       Birmingham
    Asia        Japan       South       Tokyo

The resultant XML document that will be produced is similar to the one shown below:

<continents>
    <continent name="Africa">
        <countries>
            <country>
                <countryName>Kenya</countryName>
                <county>South</county>
                <town>Mombasa</town>
            </country>
            <country>
                <countryName>Egypt</countryName>
                <county>South</county>
                <town>Cairo</town>
            </country>
        </countries>
    </continent>
    <continent name="Europe">
        <countries>
            <country>
                <countryName>England</countryName>
                <county>North</county>
                <town>Birminghan</town>
            </country>
        </countries>
    </continent>
    <continent name="Asia">
        <countries>
            <country>
                <countryName>Japan</countryName>
                <county>South</county>
                <town>Tokyo</town>
            </country>
        </countries>
    </continent>    
</continents>

What i am planning to do is read the data from the database into a JPA object. This returns a list of the following object

@Entity
@Indexed
@Table(name="TOWN")
public class Town {

    protected String continent;
    protected String country;
    protected String county;
    protected String town;

    @Id 
    @Column(name="CONTINENT")
    public String getContinent() {
        return continent;
    }

    public void setContinent(String continent) {
        this.continent = continent;
    }

    @Column(name="COUNTRY")
    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    @Column(name="COUNTY")
    public String getCounty() {
        return county;
    }

    public void setCounty(String county) {
        this.county = county;
    }

    @Column(name="TOWN")
    public String getTown() {
        return town;
    }
    public void setTown(String town) {
        this.town = town;
    }   
}

When i run the call to retrieve the rows from the database, i will get the list in the following format:

List<Town> towns = entityManager.getAllTowns();

To be able to generate the XML file, i have to iterate the list and process each of the “Town” object. I can use DOM but i feel that there will be lots of for loops and if statements to be able to generate the XML document. Is it possible to generate the XML document without having to iterate through the list to build the xml file shown above?

I have converted a JPA object to Jaxb but this was a flat relationship with a one to one mapping (i.e. no child or inner elements in the XML structure). I dont understand how to do the child elements and the conditional rules that would be required for the sample xml file.

I am using JPA/Hibernate with Spring 3. Is it possible to generate the sample xml file or do i need to do it manually (Using for loops and if statements) because of the format of the XML file?

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-06-05T04:13:56+00:00Added an answer on June 5, 2026 at 4:13 am

    I’ve generally found it easier to go the other way from what you’re doing. That is, generate the JAXB objects using XJC, and then use an orm.xml file to do the JPA mapping to the database. You can customize the generated Java objects using standard XJC plugins and JAXB configuration files.

    This approach has the advantage of maintaining only one set of Java classes (maybe with some supplemental child classes of the JAXB model), and it also has a tendency to promote a more stable XML contract.

    For some reason, people have a tendency to look down upon using a separate XML file for ORM. There are cases, though, where it makes sense, and I believe that this is one of those cases.

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

Sidebar

Related Questions

I would like to convert some value from a XML attribute into valid HTML
I would like to convert from an image (like jpg or png) to PDF.
I would like to convert this fluent approach to xml: container.Register( AllTypes.FromAssemblyNamed(Company.DataAccess) .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(), AllTypes.FromAssemblyNamed(Framework.DataAccess.NHibernateProvider)
I would like to select only few columns from a certain (Blobs) table. I
I have a table of data which I would like to order by the
I have some trouble to convert my data.frame from a wide table to a
I would like to convert a yyyy-mm-dd to something like this: Saturday, 2 October
I would like to convert BufferedImage to an image that will display on JSP
I would like to convert this string foo_utf = u'nästy chäräctörs with å and
I would like to convert my Subversion repository to Mercurial. I have a pretty

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.