xml重复元素的最佳实践 [英] best practice for xml repeating elements
问题描述
如本例所示重复 xml 元素是否可以接受?请注意,在第一个示例中,'period_data' 元素是如何直接在 'usage_history' 元素中重复的,而没有首先被包裹在类似于 'periods' 父元素的东西中.
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.
最初对我来说,包含 'periods' 父元素似乎是多余的,因为 'usage_history' 父元素中唯一的东西是 'period_data' 元素.
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.
谢谢.
<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>
与此相反...
<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.
我还要说 num_periods="2"
是错误的,因为 period_data
元素应该说明它们自己.
I would also say that num_periods="2"
is wrong, as the period_data
elements should account for themselves.
这篇关于xml重复元素的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!