Monday, July 4, 2011

HTML ELEMENTS

What is an XML Element?

An XML element is everything from (including) the element's start tag to (including) the element's end tag.

An element can contain:

* other elements
* text
* attributes
* or a mix of all of the above...

Best Naming Practices

Make names descriptive. Names with an underscore separator are nice: <*first_name>, <*last_name>.

Names should be short and simple, like this: <*book_title> not like this: <*the_title_of_the_book>.

Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.

Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."

Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).

XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.

Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.

HTML Elements

XML elements are represented by tags. Elements usually consist of an opening tag and a closing tag, but they can consist of just one tag. Opening tags consist of <, followed by the element name, and ending with >. Closing tags are the same but have a forward slash inserted between the less than symbol and the element name.

Example:


Empty elements are closed by inserting a forward slash before the greater than symbol.

Example of empty tag:


The following syntax rules are important to note, especially if you're used to working with XML where you don't usually need to worry about these rules.

All Elements Must Be Closed Properly

If you're familiar with HTML, you will know that some HTML tags don't need to be closed. In XML however, you must close all tags. This is usually done in the form of a closing tag where you repeat the opening tag, but place a forward slash before the element name (i.e. <*/child>). If you are using an empty element (i.e. one with no closing tag), you need to place a forward slash before the greater than symbol at the end of the tag (i.e. <*child />).

Example for opening/closing tags:



Tags Are Case Sensitive

All tags must be written using the correct case. XML sees as a different tag to <*Tutorial>


Wrong:


<*Tutorial>XML<*/tutorial>

Right:


<*Tutorial>XML<*/Tutorial>
<*tutorial>XML<*/tutorial>
<*TUTORIAL>XML<*/TUTORIAL>

PLEASE Remove Firstly All Asterics *



Elements Must Be Nested Properly

You can place elements inside other elements but you need to ensure each element's closing tag doesn't overlap with any other tags.


Wrong:


<*tutorial>
<*name>XML<*/tutorial>
<*/name>

Right:


<*tutorial>
<*name>XML<*/name>
<*/tutorial>

PLEASE Remove Firstly All Asterics *



Element Names

You can use any name you like for your elements as long as they adhere to the following rules:

* Element names can contain any character (including letters and numbers)
* Element names must not contain spaces
* Element names must not begin with a number or punctuation character (for example a comma or semi-colon etc)
* Element names must not start with the letters XML (whether lowercase, uppercase, or mixed case)

You shouldn't use a colon (:) in your element names, as this is reserved for another purpose.

THANK YOU