Is there any standard, de facto or otherwise, for XML documents? For example which is the "best" way to write a tag?
<MyTag />
<myTag />
<mytag />
<my-tag />
<my_tag />
Likewise if I have an enumerated value for an attribute which is better
<myTag attribute="value one"/>
<myTag attribute="ValueOne"/>
<myTag attribute="value-one"/>
For me, it is like discussing of code style for a programming language: some will argue for a style, others will defend an alternative. The only consensus I saw is: "Choose one style and be consistent"!
I just note that lot of XML dialects just use lowercase names (SVG, Ant, XHTML...).
I don't get the "no spaces in attributes values" rule. Somehow, it sends to the debate "what to put in attributes and what to put as text?".
Maybe these are not the best examples, but there are some well known XML formats using spaces in attributes:
I don't fully understand the arguments against the practice (seem to apply to some usages only) but it is legal at least, and quite widely used. With drawbacks, apparently.
Oh, and you don't need a space before the auto-closing slash. :-)
rss is probably one of the most consumed xml schemas in the world and it is camelCased.
Spec is here: http://cyber.law.harvard.edu/rss/rss.html
Granted it has no node attributes in the schema, but all the node element names are camelCased. For example:
lastBuildDate managingEditor pubDate
There is no explicit recommendation. Based on other recommendation from W3C, the one for XHTML, I've opted for lowercase:
I favour TitleCase for element names, and camelCase for attributes. No spaces for either.
As an aside, I did a quick search for Best Practices in XML, and came up with this rather interesting link: XML schemas: Best Practices.
XML Naming Rules
XML elements must follow these naming rules:
Source: W3 School
It's subjective, but if there are two words in an element tag, the readibility can be enhanced by adding an underscore between words (e.g.
<my_tag>
) instead of using no separator. Reference: http://www.w3schools.com/xml/xml_elements.asp. So according to w3schools the answer would be:The value needn't use an underscore or separator, since you are allowed spaces in attribute values but not in element tag names.