在定义 XSD 时使用属性组比使用属性有什么好处?
在定义 XSD 架构时使用属性组比使用属性有什么好处?
好的...所以我可以在其他地方声明它们并引用它们...
还有什么?
What is the benefit of using attribute groups over attributes in defining an XSD Schema?
Ok... so I can declare them elsewhere and reference them...
What else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,正如美国海关和边境保护局所说,您可以重复使用它们。 通过这种方式修改多个元素的属性也更容易。
一般来说,当我有几个合理相似的元素(除了名称和其他一些属性之外)时,我自己有时会使用它们。 因此,这些元素都共享一个或多个属性组,有时还具有附加属性。
示例:您要导出包含 40 个表的数据库。 所有表都有一个 ID 作为标识符,一些表有开始/结束日期。 其他字段也有属性。 因此,您可以为 ID 创建一个属性组,并根据需要向该组添加限制。 将为日期创建第二个属性组,包括其限制。 也许数据库结构甚至允许更多的分组。
另一种方法是创建新的复杂类型,但如果您想将子元素添加到元素中,那么您也需要将它们添加到复杂类型中。 而且您可能不希望所有元素都使用相同的复杂类型,因此当您无法使用复杂类型添加相似的属性组时,属性组非常有用。
Basically, as cbp says, you can re-use them. It's also easier to make modifications to the attributes of multiple elements this way.
In general, I myself sometimes use them when I have several elements that are reasonable similar, except for the name and a few other attributes. Thus, those elements all share one or more attribute groups and sometimes have additional attributes.
Example: you're exporting a database with 40 tables. All tables have an ID as identifier and a few have a start/end date. There are also attributes for the other fields. So you can create one attribute group for the ID, adding restrictions to that group as need be. A second attribute group would be created for the dates including their restrictions. Maybe the database structure even allows some more groupings.
An alternative method would be by creating new complex types, but if you want to add child elements to your element then you need to add those to the complex type too. And you might not want to have all your elements use the same complex type, thus attribute groups are useful where you can't use complex types to add similar groups of attributes.
您可以在不同的元素之间重复使用同一组。
You can reuse the same group across different elements.