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?

I think this is an example of a design pattern where the <altitude> element names a property of its parent element, and the property can take different forms, represented by different content models.

We get another example in the QT3 test suite, where we have

<test-case name="A">
   ....
   <result>
      <assert-eq>2</assert-eq>
   </result>
</test-case>

and then 

<test-case name="B">
   ....
   <result>
      <error-code>XPTY0004</assert-eq>
   </result>
</test-case>

In both cases <result> performs the same role in describing a property of a test-case (namely, its expected results), but for different tests, the expected result can take different forms.

It's definitely a strength of XML that it allows this kind of flexibility, and there are many ways of taking advantage of it. However, people don't often realise that in some cases they are choosing a name that describes how the element relates to its parent, and in other cases they are choosing a name that describes what kind of thing it is (its type).

JSON, of course, only allows the first kind of name - the names in a map are the names of properties of the contained object, which has no name of its own.

Michael Kay
Saxonica

> On 20 Jan 2022, at 15:14, Roger L Costello <costello@mitre.org> wrote:
> 
> Hi Folks,
> 
> Michael Kay wrote:
> 
> 	Obviously if two things are completely unrelated
> 	then it's wise to choose different names. But usually
> 	the question arises when they're a bit different,
> 	but not completely different. Discovering useful
> 	abstractions, and giving the abstractions names,
> 	is a vital part of data modelling.
> 
> Let's take a real use case.
> 
> I am working on an XML model of aircraft flights. When planning a flight, a navigator draws a series of legs that the aircraft is to fly. For each leg, the navigator specifies constraints on the aircraft's altitude: the aircraft must be at a certain altitude, at-or-above a certain altitude, or at-or-below a certain altitude. Here is an XML representation of a leg:
> 
> <leg>
>    <altitude>
>        <at-or-above>
>            <altitude>29000</altitude>
>        </at-or-above>
>    </altitude>
> </leg>
> 
> Read as: on this leg of the flight, the aircraft should be at-or-above 29,000 feet.
> 
> Notice that the XML has two <altitude> elements with different types -- one has a complexType, the other has a simpleType.
> 
> Recalling what Michael Kay said:
> 
> ... if two things are completely unrelated ...
> 
> In this case I don't think the two <altitude> elements are completely unrelated.
> 
> ... usually the question arises when they're a bit different, but not completely different ...
> 
> I think this is the case. The two <altitude> elements are different but not completely different.
> 
> The outer <altitude> element says,
> 
> 	The aircraft's altitude must satisfy
> 	the constraint specified (in the
> 	element's content). 
> 
> The inner <altitude> element says,
> 
> 	Here is an altitude. 
> 
> Do you agree that the two <altitude> elements are different but not completely different?
> 
> Again, recalling what Michael Kay said:
> 
> ... Discovering useful abstractions, and giving the abstractions names, is a vital part of data modelling.
> 
> I think there are two abstractions: (1) Constraints on an altitude, and (2) a specific altitude.
> 
> Does this mean an element that implements one abstraction should have a different name than an element that implements another abstraction? 
> 
> Question: Are you okay with the two <altitude> elements? Or should they have different names?
> 
> /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
> 



[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