简体   繁体   English

xml重复元素的最佳实践

[英]best practice for xml repeating elements

Is it acceptable to repeat xml elements as shown in this example? 如本示例所示,重复xml元素是否可以接受? 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. 请注意,在第一个示例中,如何直接在“ usage_history”元素内直接重复“ period_data”元素,而不先将其包装在诸如“ periods”父元素之类的内容内。

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. 最初,对我来说,将'periods'父元素包括在内似乎是多余的,因为'usage_history'父元素内唯一的东西还是“ period_data”元素。

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>

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. 我还要说num_periods="2"是错误的,因为period_data元素应该说明自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM