I came across this list of W3C XML Schema: DOs and DON'Ts and the part that says DO NOT use complex types kind of surprises me.
I don't find any trouble in using <xs:complexType name="SomeNewType">
and I don't see why using <xs:group name="someNewElement">
is better than using a complexType.
Should complexType really need to be avoided?
If so, why? What is so problematic about it?
What should be used instead?
For almost any language sufficiently complex and powerful to be interesting, different people will have different views on the best way to use that language.
You ask "should complexType really be avoided?" As you've seen, in the document you point to Kohsuke Kawaguchi (who was a member of the working group that designed XSD and has written several important XSD tools, including one of the first XSD validators) advises users to avoid certain constructs in XSD, including complexType, often on the grounds that the ratio of their advantages to their disadvantages (in particular: their complexity) is poor. You can (and indeed you must) make up your own mind on the persuasiveness of KK's arguments.
Since (as far as I can see) your question amounts to asking "is KK right?", I gather that you don't feel entirely comfortable making up your own mind, or at least that you are curious and want to know what others think.
In general, it's safe to say that many users of XSD, and many creators of XSD tools, disagree with KK. They find the ability to derive complex types from other complex types helpful, and they use it.
It's equally safe to say that many others agree with KK that this or that construct of XSD is too complex and is better avoided. Some who feel this way write documents describing "best practices" which lay out constructs to use and constructs to avoid; sometimes the contents of such documents is useful and sometimes not. Many who agree most fervently with KK about XSD's complex types do not use XSD at all, when they can avoid doing so: they prefer Relax NG (or in some cases, DTDs or Schematron).
In other words: the opinions of qualified observers vary, as do those of unqualified observers. I know some very smart people who disagree with KK on this question. And I also know that KK himself, and some of those who agree with him, are also very smart. I have no intention of choosing a side here.
Finally, you ask If it is problematic, why does it exist in the language construct in the first place? Any construct in any language exists because those who designed the language thought it was worth including. In the case of XSD and complex types, that means: complex types are in XSD as nameable objects because essentially everyone in the responsible working group wanted them in the language. This does not prevent them from being problematic: like everyone else, people of great technical skill can make mistakes, and groups that must seek consensus can under the right circumstances produce designs that no one really likes very much (but which everyone prefers to the alternative of not having the construct in question at all; sometimes compromise is the only way to get something done).
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With