XML Syntax (1)
The syntax of XML is very simple. The following are the sytax rules:
- A XML document must contain a pair, and only a pair, of root tags
- All XML elements must have a opening tag and a closing Tag.
- XML tags are case sensitive.
- An element in XML can has its child element.
- All elements in XML must be properly nested within each other.
- XML attribute values must be quoted.
As you may know that, HTML is quite forgiving when it comes to tag placement,
missing tags, and attribute values. A web browser, for example, will correctly
interpret an HTML page even if you forget to put a closing tag, like:
<p>Welcome to my website
<li>This is an element of a list
In XML, all elements must have a closing tag:
<firstname>Michael</firstname>
<lastname>Smith</lastname>
In HTML, tags are not case sensitive. you can use a tag like "<table>",
or "<TABLE>", or "<Table>". They all are valid.
But in XML, "<table>", or "<TABLE>", or "<Table>"
will be three different tags because XML Tags are case sensitive. So you must
write your opening and closing tags with the same case:
<Description>This is incorrect</description>
<description>This is correct</description>
In HTML, even the elements are improperly nested, it may still work.:
<b><i>This text is bold and italic</b></i>
XML Elements Must be Properly Nested:
<b><i>This text is bold and italic</i></b>
In the example above, "Properly nested" simply means that since the
<i> element is opened inside the <b> element, it must be closed
inside the <b> element.
XML Documents Must Have a Root Element.
|