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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:31:33+00:00 2026-05-13T20:31:33+00:00

i have a database that contains countries and cities. i want to export this

  • 0

i have a database that contains countries and cities. i want to export this information to a xml document, but wonder how to structure it.

should i do it like this:

<country>
 <name>Canada</name>
 <city>
  <name>Toronto</name>
  <population>1423200</population>
 </city>
 <city>
  <name>Ottawa</name>
  <population>1423200</population>
 </city>
</country>

or like this:

<country>
  <name>Canada</name>
  <cities>
     <city>
      <name>Toronto</name>
      <population>1423200</population>
    </city>
    <city>
      <name>Ottawa</name>
      <population>1423200</population>
    </city>
  </cities>
</country>

or like this:

<entity>
 <country>Canada</country>
 <city>Ottawa</city>
 <city_population>1423200</city_population>
</entity>
<entity>
 <country>Canada</country>
 <city>Toronto</city>
 <city_population>1423200</city_population>
</entity>

what are the pros and cons with each of them? is there another way of structuring?

which of them is best for future changes (adding data).

my first time to structure in xml, so would be great with feedbacks/hints!

  • 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-13T20:31:33+00:00Added an answer on May 13, 2026 at 8:31 pm

    You should structure you XML Documents in the same manner you would structure you class in the code. So as cities population is property of the city itself – it should be child of the city node. I would go for the 2nd structure.

    Plus it’s more mnemonic about your objects. For example it’s not clear what ‘entities’ stays for in your second solution.

    Plus it has less data repetition, as you have to state the country=canada in every entity. I would make a change to you first solution, though. Put the Country element in a collection:

    <countries>
    <country>
     <name>Canada</name>
     <cities>
     <city>
      <name>Toronto</name>
      <population>1423200</population>
     </city>
     <city>
      <name>Ottawa</name>
      <population>1423200</population>
     </city>
     </cities>
    </country>
    </countries>
    

    It will help you extend later your data.

    EDIT: In general, when you have a repetition of objects it’s better to wrap them in a ‘collection’ element. It’s a good practice since you can add properties into the collection itself and some other benefits – you won’t have iterate in to the parents’ elements and choose which one belongs to the same type.

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

Sidebar

Related Questions

Suppose that I have a database table that contains information on cities across the
I have SQL Server Compact 3.5 database that contains account information. But everytime I
I have a database that contains a table that looks a bit like this:
I have this MySQl database that has a table which contains a column that
We have a database that contains information about time booked to projects. We have
I have a database table that contains blog posts. I want to show on
I have one database that contains all of user information including name. Then there
I have a database schema that contains multiple tables with different names, but all
I have this database table that contains emails like 300 records, emails{email,name,join_date); and I
I have a SQL Server database that contains an xml column. I need 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.