Reputation: 1271
We use a Garden of Eden XML Schema design pattern. Some sources states that an attributes must be global. Other sources mentions only global elements and types, but doesn't restrict attribute usage. Here is an example of local attributes.
Should I use global attributes?
As I see global attributes have to be qualified in most use cases. But some sources says that local attributes should be unqualified (and I guess non-local one should be unqualified too for consistency):
5.2 attributeFormDefault
This attribute setting should always be set to unqualified. The time to justify the setting of this value is not worth any incremental value in the understanding of this concept. Industry best practices recommend always setting this attribute value to unqualified.
Here is a hack with attributeGroup which allows attributes to be unqualified. But I still don't understand whether global attributes should be used or not.
Upvotes: 0
Views: 165
Reputation: 21658
Most likely the answer to your question should be "don't use global attributes, unless you really have to". Because of the unless
... I don't think there's one answer that would work regardless; in other words, the context is what matters here.
A global attribute is basically one that "belongs" to the qualifying namespace; this is the mechanism that ensures that my carefully named attribute will not collide with yours; and that its semantics stand out. Imagine the usefulness of xsi:type attribute... unqualified.
Some models will accept qualified attributes as the only way to provide extensions to an existing model (see ##other use) - you have no choice then.
Some processing models (that is how you consume your XML) may benefit from using global attributes, if only because matching those attributes in an XSLT (as an example) or streaming type API may amount for a much more "context free" and (guaranteed) unambiguous interpretation of the associated value.
Other processing models (e.g. those that rely on XSD to code bindings, JAXB is one) make the above distinction irrelevant.
Upvotes: 1