XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Do not use the same tag name for different things ...Do you agree?

If it was shredded into a database there might be two tables each with a column named Tank. No problem with that. So why would the XML equivalent need special treatment? 

On Wed, 19 Jan 2022 at 18:53, Roger L Costello <costello@mitre.org> wrote:
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

--
----
Stephen D Green


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS