best practice for xml repeating elements

余生长醉 提交于 2019-12-11 00:59:40

问题


Is it acceptable to repeat xml elements as shown in this example? Notice in the first example how the 'period_data' element is just repeated directly inside the 'usage_history' element without first being wrapped inside something like a 'periods' parent element.

Initially it seems reduant to me to include the 'periods' parent element as the only thing inside the 'usage_history' parent are 'period_data' elements anyway.

Thank you.

<usage_history num_periods="2">
    <period_data billing_year="2013" billing_period="2">
        content...
    </period_data>
    <period_data billing_year="2013" billing_period="1">
        content...
    </period_data>
</usage_history>

as opposed to this...

<usage_history>
    <periods num_periods="2">
        <period_data billing_year="2013" billing_period="2">
            content...
        </period_data>
        <period_data billing_year="2013" billing_period="1">
            content...
        </period_data>
    </periods>
</usage_history>

回答1:


Yes. That is fine. There is no need for an extra enclosing element.

I would also say that num_periods="2" is wrong, as the period_data elements should account for themselves.



来源:https://stackoverflow.com/questions/15824975/best-practice-for-xml-repeating-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!