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"/>
The following are not valid XML names: <2do>—Names must not begin with a digit. <-name>—Names cannot start with special characters such as a hyphen or period. <x+2=4>—Names cannot contain special characters other than the period, hyphen, underscore, and colon.
Another element can exist within an element, but each element's start tag must have a corresponding end tag before another element's start tag begins. This is the right example for nesting elements properly in a xml document. Nesting of xml elements must be proper, in a well-formed xml document.
Names must not contain special characters. This is recommended to be similar to other XML standards. Note that the underscore is allowed. This is not the same as other standards.
"Empty XML Elements An element with no content is said to be empty. In XML, you can indicate an empty element like this: <element></element> or you can use an empty tag, like this (this sort of element syntax is called self-closing): <element /> The two forms above produce identical results in an XML parser."
I suspect the most common values would be camelCased - i.e.
<myTag someAttribute="someValue"/>
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).
- Element names are case-sensitive - Element names must start with a letter or underscore - Element names cannot start with the letters xml(or XML, or Xml, etc) - Element names can contain letters, digits, hyphens, underscores, and periods - Element names cannot contain spaces
Any name can be used, no words are reserved (except xml).
- Create descriptive names, like this: <person>, <firstname>, <lastname>. - Create short and simple names, like this: <book_title> not like this: <the_title_of_the_book>. - Avoid "-". If you name something "first-name", some software may think you want to subtract "name" from "first". - Avoid ".". If you name something "first.name", some software may think that "name" is a property of the object "first". - Avoid ":". Colons are reserved for namespaces (more later). - Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software doesn't support them.
There are no naming styles defined for XML elements. But here are some commonly used:
- Lower case <firstname> All letters lower case - Upper case <FIRSTNAME> All letters upper case - Underscore <first_name> Underscore separates words - Pascal case <FirstName> Uppercase first letter in each word - Camel case <firstName> Uppercase first letter in each word except the first
reference http://www.w3schools.com/xml/xml_elements.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With