Reputation: 44398
I start with XML and almost all everything that is involved, working in XML Oxygen editor. I have met 3 basic design patterns of XSD schema and I don't know which one should suit my needs the most and in general.
I want to create a large schema validating a XML file containing teams with players.
My question is which one is the best and is considered to be the most well-arranged, user-friendliest and professional for my purpose and in general? Which one is practically the most common and what do you recommend me as to the beginner with XML to the future?
Here are my samples of all designs I know:
Matryoshka
I have started with this one, because it was simply understandable. No references at referencing to types all. I am sure this one is suitable for tiny files.
<xsd:element name="player">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="skill" type="xsd:float"/>
<xsd:element name="nationality">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Venetian Blind
This is my the most favourite one, because of defining the sctructire in the beginning and then all types of elements.
<xsd:element name="player" type="playerType"/>
<xsd:complexType name="playerType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="skill" type="xsd:float"/>
<xsd:element name="nationality" type="nationalityType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="nationalityType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}"/>
</xsd:restriction>
</xsd:simpleType>
Salami Slice
This one was the most recommended me, although I see that XML file can contain only one of elements as well as all of them. I am quite confused of this design.
<xsd:element name="player">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="name"/>
<xsd:element ref="skill"/>
<xsd:element ref="nationality"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="skill" type="xsd:float"/>
<xsd:element name="nationality">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Upvotes: 3
Views: 4654
Reputation: 111541
My question is which one is the best and is considered to be the most well-arranged, user-friendliest and professional for my purpose and in general?
There is no best XSD design pattern in general — just better ones per particular purposes.
For a good treatment of the relative advantages XSD design patterns, see
If you're working within a sector that has established XSDs, follow the pattern used there. If your company has established conventions, follow those.
If you're learning, have no driving outside influences, and are wondering...
...what do you recommend me as to the beginner with XML to the future?
Here's a reasonable approach for a beginner:
This way you'll develop a working understanding of the advantages of each approach and, should you need to adopt a uniform strategy on a larger scale in the future, you'll have developed the experience and intuition to make an informed decision.
Upvotes: 2