Hi Folks,
Consider this XML document:
<Items>
<Aquarium>
<Tank>40 gallon capacity</Tank>
</Aquarium>
<Abrams>
<Tank>M-1A2C</Tank>
</Abrams>
</Items>
Notice that there are two <Tank> elements. They have completely different meanings: the first is a tank that we put fish in, the second is a tank that is used in military battles.
Same tag name, totally different meanings.
Are you okay with that? That is, are you okay with using the same tag name for two different things?
Below I make this argument: Never use the same tag name for two different things.
Here's why:
Recall the DRY (Don't Repeat Yourself) principle. Consider an XML Schema for the above XML. Assume the type for the aquarium tank is different than the type for the military tank:
<xs:element name="Title" type="AquariumTankType"/>
<xs:element name="Title" type="MilitaryTankType"/>
The DRY principle says: Declare once, ref often. That is, in the XML Schema globally declare the Title element once and ref to it multiple times. But we can't declare Title only once since they have different types. There must be at least one Title element that is locally declared. The DRY principle must be violated. That is bad design.
Question: Beside violating the DRY principle, are there other reasons to avoid using the same tag name for different things?
Here's a better design:
<Items>
<Aquarium>
<Tank>40 gallon capacity</Tank>
</Aquarium>
<Abrams>
<BattleTank>M-1A2C</BattleTank>
</Abrams>
</Items>
Now an XML Schema can declare Tank and BattleTank globally and ref to them. DRY is intact.
Question: do you agree that XML documents should not use the same tag name for different things?
/Roger
_______________________________________________________________________
XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.
[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php