decorative banner

Working with XML elements whose content varies in structure


    Unlike databases where each record has the same structure and fields, XML elements may have structure and fields that vary. For example, one <product> element may have children <price> and <discount>, and some other <product> element may have children <price>, <sale_price>, and <sale_area>.

    <products>

    <product>

    <name>Toy Train</name>

    <price>34.21</price>

    <discount>15%</discount>

    </product>

    <product>

    <name>Game Console</name>

    <price>199.95</price>

    <sale_price>149.99</sale_price>

    <sale_area>worldwide</sale_area>

    </product>

    </products>

    The XML data source editor shows you the union of the tags seen on the various <product> elements. You need to understand how to determine when the various child elements are present in a given element. This is based on the semantics of the data.

    Your Web page can deal with this varying structure by using Containers with Show/Hide content options (see Creating conditional regions). Create a Container object with a Show/Hide option. Suppose you want to show some part of the page dealing with the sale price if the <sale_price> element is present for a given product. To do this, enclose the content in the container object, set the condition on the container object to Hide If Field Is Empty, and set the field to product/sale_price.

    There are other tests that can be used to perform similar kinds of functions.