Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case conventions on element names?

People also ask

Are element names case sensitive in XML?

XML tags are case sensitive.

Do XML elements have to be lowercase?

The original intent for XML casing was lower case with hyphens. It's case sensitive and doesn't require you follow that convention -- so you can do whatever you want.

Can XML elements have capital letters?

Each word in the name of a Legal XML element or attribute should begin with a capital letter. The names of Legal XML elements and attributes should semantically describe the data or information they contain.


Most XML standards originating from the W3C tend to use lower case with hyphens.

There is a philosophical distinction between seeing XML as a format for platform neutral documents, which W3C standards try to encourage, and languages such as XAML which see XML as a serialisation of a platform specific object graph.

If you're not using XML as a platform neutral document format, but as an application specific serialisation, then you might as well save yourself some bother and have a 1:1 correspondence between the XML names and the platform specific names. But almost any other object graph format is better than XML for that purpose.

If you are, then you might want to fit in with XHTML, XSLT, SVG, XProc, RelaxNG and the rest.


Not that it matters, but I've always been partial to PascalCase for Elements and camelCase for attributes:

<Root>
  <ParentElement attributeId="1">
    <ChildElement attributeName="foo" />
  </ParentElement>
</Root>

There is no formal recommendation.

Since XML was designed with the twin purposes of holding documents and exchanging information between disparate systems, it was designed so as to be able to match the applications using it.

So .Net XML tends to use ProperCasing (witness XAML), while other XML will use camelCasing, python_conventions, dot.naming, and even COBOL-CONVENTIONS. The W3C seems to like lower-case-with-dashes-quite-a-bit (e.g. XSLT) or justlowercasewordssmashedtogether (e.g. MathML).

I like all lower case and no underscores, since that means less use of the [Shift] key, and my fingers are a little lazy. :)


To add to Metro Smurf's answer.

The National Information Exchange Model (NIEM: http://en.wikipedia.org/wiki/National_Information_Exchange_Model) says to use:

  • Upper CamelCase (PascalCase) for elements.
  • (lower) camelCase for attributes.

The NIEM makes for a good option when you're looking to conform to some standard.