OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   CamelCase names for XML elements vs. property names for Java beans

[ Lists Home | Date Index | Thread Index ]
  • From: "Tolkin, Steve" <Steve.Tolkin@fmr.com>
  • To: "'xml-dev@ic.ac.uk'" <xml-dev@ic.ac.uk>
  • Date: Tue, 18 Jan 2000 12:45:47 -0500

In XML both object and their properties can be represented by
elements, with a object being a non-leaf element and a property a leaf
element.  (See quote from BizTalk guidelines below.)  But this
distinction is not a strong one, e.g. the leaf element <name> can
later be changed to a non-leaf element with children <firstName> and
<lastName>.  (This is unlike the relational model of databases, where
the distinction between tables and columns is a strong one.)

Q1. Should leaf elements use a different naming convention than
non-leaf elements?
I think these should use the same convention, to make it easy to
"migrate" between whether an element is a leaf or non-leaf element.

Q2. Should elements use lowerCamelCase or UpperCamelCase?
I at first adopted UpperCamelCase for two reasons:
* It looks much more natural to ordinary end users, who might see the
XML tags e.g. in the IE tree control.  For example "PurchaseOrder"
sems much more like the natural language "Puchase Order" than does
"purchaseOrder".
* XML elements are more likely to be represented as classes than as
properties (because elements themselves can have XML attributes).

But this is in conflict with the naming convention for Java beans: 
the name of a bean property must start with a lowercase letter.  
(Actually this is not a requirement, but if it is not followed the java
programmer must explictly write a bunch of code instead of having the
getFoo and setFoo accessors "for free".)  It seems desirable, but
highly unlikely, hat Java beans change to frst try to find a property
named Foo i.e. starting with an uppercase letter.

Summary: there are at least three reasonable naming conventions
and here are their pros and cons.
1. All Elements UpperCamelCase: 
Pro: Elements names are consistent so it is easy to "migrate".
Pro: Has "user-friendly" tag names.
Con: Violates BizTalk guidelines.
Con: Hard to use with Java beans.

2. All Elements lowerCamelCase: 
Pro: Elements names are consistent so it is easy to "migrate".
Pro: Easy to use with Java beans
Con: Violates BizTalk guidelines.
Con: Does not have "user-friendly" tag names.

3. Non-leaf elements are UpperCamelCase and 
leaf elements are lowerCamelCase:
Pro: Follows BizTalk guidelines.
Even: Leaf elements easy to use with Java beans, but not non-leaf elements.
Even: Leaf elements have "user-friendly" names, but not non-leaf elements.
Con: Element names are not consistent so it is hard to "migrate".

What approach are people using?  What other factors matter here?

Steven Tolkin 

P.S.  I know we could use lowercase_with_underscore-or-dash names, 
so please do not suggest this.

In the BizTalk Framework Document Design Guide
(http://www.BizTalk.org/Resources/frame081.asp).
    Names and Cases: Names should use the style called
"CamelCase." If an element reflects a thing (an object, a class or a
table name), use UpperCamelCase; if it is a property, a reference,
etc., use lowerCamelCase.
    Expressing Data: All simple data (trees, columns, rows, objects,
properties, etc.) should be expressed as elements and subelements, not
attributes.

An excerpt from beans_101.pdf downloaded 2000-01-14 from 
http://java.sun.com/beans/docs/spec.html
8.2 Overview of Design Patterns
... For example the use of getFoo and setFoo methods to
retrieve and set the values of a "foo" property. 
[The first character after the accessor prefix of is, get, or set
is forced to lowercase.  This only appears in the examples.
It is a subtle point that should have been stated explicitly.  
Steve]

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ or CD-ROM/ISBN 981-02-3594-1
Please note: New list subscriptions now closed in preparation for transfer to OASIS.






 

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

Copyright 2001 XML.org. This site is hosted by OASIS