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?

Hi Roger,

> Question: Beside violating the DRY principle, are there other reasons to avoid using the same tag name for different things?

If you mean having the same name() (the XPath function), then yes, this is to be avoided.

However, it is OK to have elements with the same local-name() that are in different namespaces:

restaurant:table,   sql:table, word:table, furniture:table, html:table

architecture:column,  sql:column,  table:column, army:column

css:style, architecture:style, fashion:style

language:greek, student-life:greek

calendar:march, army:march, ..., etc

This is one of the main reasons why we have and use namespaces.

Thanks,
Dimitre


On Wed, Jan 19, 2022 at 10:53 AM 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



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
 


[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