Representing Deeply Nested Data in XML

Asked by At

I have data of the following data schema:

Software
+
|
|  Microsoft
|   +
|   +--->Windows 10
+-->+
|   +--->Windows 7
|
| Google
|   +
|   +-->Chrome
+-->+
    +-->Orkut

I want to nest this optimally that is redable by any XML Parser, my initial idea was to do it like this:

<?xml version="1.0"?>
<Software Name = "Company Software">
  <HeadProduct Name = "Google">
    <Product>Chrome</Product>
    <Product>Orkut</Product>
  </HeadProduct>
  <HeadProduct Name = "Microsoft">
    <Product>Windows 10</Product>
    <Product>Windows 7</Product>
  </HeadProduct>
</Software>

However, my gut tells me this is a problem and definitely not what I intended. Here is why:

While Google and Microsoft are just attributes, Windows 10 and Orkut are elements. I my mind somewhere I would have liked Google and Microsoft as elements as well. To summarize, I don not think I have correctly translated the schema to XML.

Any help will be beneficial.

1 Answers

1
Community On Best Solutions

If you want to avoid attributes, this may work for you.

<?xml version="1.0"?>
<Software>
    <Name>Company Software</Name>
    <HeadProducts>
        <HeadProduct>
            <Name>Google</Name>
            <Products>
                <Product>Chrome</Product>
                <Product>Orkut</Product>
            </Products>
        </HeadProduct>
        <HeadProduct>
            <Name>Microsoft</Name>
            <Products>
                <Product>Windows 10</Product>
                <Product>Windows 7</Product>
            </Products>
        </HeadProduct>
    </HeadProducts>
</Software>