views:

48

answers:

2

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?

+1  A: 

You can reuse the same group across different elements.

cbp
+1  A: 

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.

Workshop Alex