In this tutorial you will learn about the XML Syntax and its application with practical example.
Here is quick list of syntax rules that must be followed while creating an XML Document.
XML Documents Must Have a Root Element
An XML Document consists of a container element know as root element and other elements placed inside the root element.
In the below example <inbox>…</inbox> is acting as root element.
1 2 3 4 5 6 7 8 9 10 11 12 |
<inbox> <message id="1"> <from>John</from> <subject>Test Message 1</subject> <body>Hello John!</body> </message> <message id="2"> <from>Chris</from> <subject>Test Message 2</subject> <body>Hello John!</body> </message> </inbox> |
XML Elements Must Have a Closing Tag
All XML element must be ended using a closing tag. It is illegal to remove closing tag.
XML Tags are Case Sensitive
XML tags are case sensitive. The tag <Message> is different from the tag <message>.
Start and End tags must be written in the same case.
1 2 |
<Message>This is incorrect</message> <message>This is correct</message> |
XML Elements Must be Properly Nested
All XML elements must be properly nested within each other. As child element should be closed before parent element.
XML Attribute Values Must be Quoted
Like HTML elements XML elements can have attributes in name/value pairs, and this attribute values must always be quoted properly.