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"/>
Many document centred XML dialects use lower case basic Latin and dash. I tend to go with that.
Code generators which maps XML directly to programming language identifiers are brittle, and (with the exception of naive object serialisation, such as XAML) should be avoided in portable document formats; for best reuse and information longevity the XML should try to match the domain, not the implementation.
I suspect the most common values would be camelCased - i.e.
In particular, the spaces cause a few glitches if mixed with code-generators (i.e. to [de]serialize xml to objects), since not many languages allow enums with spaces (demanding a mapping between the two).
I normally align XML naming convention with the same naming convention in other parts of code. The reason is when I load the XML into Object its attributes and element names can be referred as the same naming convention currently used in the project.
For example, if your javascript using camelCase then your XML uses camelCase as well.
Microsoft embraces two convention:
For configuration, Microsoft uses camelCase. Look at Visual Studio config file. For VS2013, it is stored in:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe.config
Example:
Example:
XML Naming Rules
XML elements must follow these naming rules:
Any name can be used, no words are reserved (except xml).
Best Naming Practices
Naming Styles
There are no naming styles defined for XML elements. But here are some commonly used:
reference http://www.w3schools.com/xml/xml_elements.asp
I have been searching a lot for a good approach, also reading this thread and some others and I would vote for using hyphens.
They are used broadly in ARIA ( https://developer.mozilla.org/de/docs/Web/Barrierefreiheit/ARIA ) which can be seen in many source codes and are therefore common. As already pointed out here, they are certainly allowed, which is also explained here: Using - in XML element name
Also as a side benefit: When writing HTML in combination with CSS, you often have classes whose names use hyphens as separator by default as well. Now, if you have custom tags that use CSS classes or custom attributes for tags that use CSS classes, then something like:
<custom-tag class="some-css-class">
is more consistent and reads - in my humble opinion - much nicer than:
<customTag class="some-css-class">