2

I'm designing an XML response for a consuming application to take in, and I'm weighing two different designs. Currently I have a design as follows (where the Product element can repeat):

<Response>
    <AccountType>
    <ProductType>
    <Products>
       <Product>
           <ProductID />
           <ProductStatus />
           <ProductName />
       </Product>
       <Product>
           <ProductID />
           <ProductStatus />
           <ProductName />
       </Product>
    </Products>
</Response>

An alternate design is:

<Response>
    <AccountType>
    <ProductType>
    <Product>
        <ProductID />
        <ProductStatus />
        <ProductName />
    </Product>
    <Product>
        <ProductID />
        <ProductStatus />
        <ProductName />
    </Product>
</Response>

In the first design I have a master element called Products, under which each Product element exists and can repeat within Products. The second design is a little flatter - where Product exists under the main Response node.

Which one of the two is more optimal for a consuming application to read from and process?

15

The one that wraps all of the products into a single element. You can treat it as a collection in most programming languages that offer serialization/deserialization.

See XML Serialization of Arrays and Collections

Arrays and collections can be serialized to XML. The standard action when using the default serializer is for the name of the collection property to be added to the XML, with a contained element for each item named according to the items' data types...

2

If you're processing it with XPath or XSLT it doesn't make much difference. If you're using a programming language less well adapted to XML, the wrapper element probably makes life easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.