0

I am forced to use XML for exchanging information about oders of products. The product might contain sub assemblies that in turn may also contain sub assemblies. I envisioned the following structure, but I am not sure if it is valid to do so in XML.

<?xml version="1.0" encoding="ISO-8859-1"?>
<Order>
    <Items>
        <Item>
            <Name>Assembly A</Name>
            <Items>
                <Item>
                    <Name>Assembly B</Name>
                    <Items>
                        <Item>
                            <Name>Assembly C</Name>
                            <Items />
                        </Item>
                        <Item>
                            <Name>Assembly D</Name>
                            <Items />
                        </Item>
                    </Items>
                </Item>
                <Item>
                    <Name>Assembly E</Name>
                    <Items />
                </Item>
            </Items>
        </Item>
    </Items>
</Order>

I truncated all "unnecessary" information to make the example as minimal as possible.

I am not sure if using the nesting is okay, because a colleague told me that it does not conform with XML standards.

I chose the structure because every item/assembly in it self is completly consistent. That means I can parse any level of the hierarchy based on the same "template".

Could you please give me advise if such a structure is valid and adviseable?

wrYch
  • 11
  • 2
  • There is nothing wrong with this XML structure (Simple litmus test: When you open the XML in a browser and it gets displayed without any errors, then it conforms to XML standards.) – Tomalak Jan 07 '20 at 16:47
  • Thanks, I appreciate the answer! – wrYch Jan 07 '20 at 16:48
  • Whether it is a good fit for the problem you're trying to solve, depends. Without knowing any details of your task - I can follow this structure easily and it will be easy to consume because it's very regular. – Tomalak Jan 07 '20 at 16:49
  • Your colleague may have meant to criticize the design as being overly generic: An `Item` element name conveys little semantic information. As @Tomalak mentions, whether your design is ideal depends upon requirements beyond what you've mentioned. (Note that such design questions may be considered to be opinion-based or too broad for this site.) Somewhat related: [Can I validate polymorphic XML elements based on a child Type element value?](https://stackoverflow.com/q/57684809/290085) – kjhughes Jan 07 '20 at 19:57
  • Thank you all for the answers. They gave me a good feeling about the flaws and advantages of the design. I will try to find more specific names, though. Item is a bit too generic. On the usage, the XML file is used to exchange information about the orders between two softwares, and one of them can only handle XML. – wrYch Jan 08 '20 at 06:23

0 Answers0