The syntax rules for
XML are very simple and strict. These are easy to learn and use.
Because of this, creating software that can read and manipulate XML is very
easy. Xml enables an user to create his own tags.
Note - XML documents use a
self-describing and simple syntaxLet's develop a simple XML document :
<?xml version="1.0"
encoding="ISO-8859-1"?> <E-mail> <To>Rohan</To> <From>Amit</From> <Subject>Surprise....</Subject> <Body>Be ready for a cruise...i will catch u tonight</Body> </E-mail> |
The XML declaration should always be included. It defines the XML version and the character encoding used in the document. In this case the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set.
<?xml version="1.0" encoding="ISO-8859-1"?> |
<E-mail> |
<To>Rohan</To> <From>Amit</From> <Subject>Surprise....</Subject> <Body>Be ready for a cruise...i will catch u tonight</Body> |
</E-mail> |
Now let's discuss its syntax-rules which are very simple to learn.
All XML elements must have a closing tag
In XML all the elements must have a closing tag like this:<To>Rohan</To> <From>Amit</From> |
XML tags are case sensitive
XML tags are case sensitive. The tag <To> is different from the tag <to>.Hence the opening and closing tags must be written with the same case:<To>Rohan</To> <to>Rohan</to> |
XML Elements Must be Properly Nested
Improper nesting of tags makes no sense to XML. In XML all elements must be properly nested within each other like this in a logical order:<b><i>Hi , how are you.....</i></b> |
XML Documents Must Have a Root Element
All XML documents must contain a single tag pair to define a root element. All other elements must be written within this root element. All elements can have sub elements called as child elements. Sub elements must be correctly nested within their parent element:<root> <child> <subchild>.....</subchild> </child> </root> |
Always Quote the XML Attribute Values
In XML the attribute value must always be quoted. XML elements can have attributes in name/value pairs just like in HTML. Just look the two XML documents below.The error in the first document is that the date and version attributes are not quoted .
<?xml version=1.0 encoding="ISO-8859-1"?>
<E-mail date=12/11/2002/>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<E-mail date="12/11/2002"/>
|
With XML, White Space is Preserved
With XML, the white space in a document is preserved .So a sentence like this : Hello How are you, will be displayed like this:
Hello How are you,