Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard naming convention for XML elements? [closed]

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"/> 
like image 443
tpower Avatar asked Jan 14 '09 10:01

tpower


People also ask

Which of the following is not a valid naming rule in XML?

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.

What are the elements naming and nesting conventions in XML?

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.

Are underscores allowed in XML?

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.

Can XML have empty tags?

"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."


2 Answers

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).

like image 170
Marc Gravell Avatar answered Nov 13 '22 23:11

Marc Gravell


XML Naming Rules

XML elements must follow these naming rules:

    - 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).

Best Naming Practices

    - 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. 

Naming Styles

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

like image 32
Farhad Maleki Avatar answered Nov 13 '22 23:11

Farhad Maleki