Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! :)

For my application I will have one XML file which will contain multiple tables inside. It will be for application support. Inside will be different data and settings. I didn't need XML for something similar yet and I'm not sure how to format/design this XML structure.
I created two sample XML files below. Which approach/design should I use and why this and not the other one? Which is common approach if you would like to have multiple tables in one XML file?

Design 1:
<pre lang="xml"><?xml version="1.0" encoding="utf-8" ?>
<root>

  <Customers>
    <Customer>
      <Id>1</Id>
      <FirstName>Joe</FirstName>
      <Surname>Doe</Surname>
    </Customer>
    <Customer>
      <Id>2</Id>
      <FirstName>Mary</FirstName>
      <Surname>Brown</Surname>
    </Customer>
    <Customer>
      <Id>3</Id>
      <FirstName>Paul</FirstName>
      <Surname>Smith</Surname>
    </Customer>
  </Customers>

  <Categories>
    <Category>
      <Id>1</Id>
      <Name>Beverages</Name>
    </Category>
    <Category>
      <Id>2</Id>
      <Name>Grains</Name>
    </Category>
  </Categories>

  <Products>
    <Product>
      <Id>1</Id>
      <Name>Tea</Name>
    </Product>
    <Product>
      <Id>2</Id>
      <Name>Cereals</Name>
    </Product>
  </Products>
</root>



Design 2:

<pre lang="xml"><?xml version="1.0" encoding="utf-8" ?>
<root>
    <Customer>
      <Id>1</Id>
      <FirstName>Joe</FirstName>
      <Surname>Doe</Surname>
    </Customer>
    <Customer>
      <Id>2</Id>
      <FirstName>Mary</FirstName>
      <Surname>Brown</Surname>
    </Customer>
    <Customer>
      <Id>3</Id>
      <FirstName>Paul</FirstName>
      <Surname>Smith</Surname>
    </Customer>

    <Category>
      <Id>1</Id>
      <Name>Beverages</Name>
    </Category>
    <Category>
      <Id>2</Id>
      <Name>Grains</Name>
    </Category>

    <Product>
      <Id>1</Id>
      <Name>Tea</Name>
    </Product>
    <Product>
      <Id>2</Id>
      <Name>Cereals</Name>
    </Product>

</root>




Both actually contain the same data, but it present differently. I think "Design 1" is more expandable for the future if I add more information to specific table.

Thanks, for all advices.
Posted

To me, Design 1 from clean, understandable, maintainable and easier to parse.
 
Share this answer
 
Comments
Bil2y 23-Feb-11 1:39am    
Thank you for your opinion.
Design your tables in SqlServer. Write a small application to load them into a DataSet and then use the DataSet.WriteXML()[^] method to create your XML file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900