Web Technologies - Old Questions
10. Discuss the rules of writing XML document.
The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.
Rules for writing XML document:
1. All XML Elements Must Have a Closing Tag. In XML, it is illegal to omit the closing tag. All elements must have a closing tag:
E.g. Correct: <p>This is a paragraph.</p>
Incorrect: <p>This is a paragraph.
2. XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and closing tags must be written with the same case:
E.g. Incorrect: <Message>This is incorrect</message>
Correct: <message>This is correct</message>
3. In XML, all elements must be properly nested within each other:
E.g. Incorrect: <b><i>This text is bold and italic</b></i>
Correct: <b><i>This text is bold and italic</i></b>
4. XML Documents Must Have a Root Element. XML documents must contain one element that is the parent of all other elements. This element is called the root element.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
5. XML Attribute Values Must be Quoted.
<note date="06/01/2012">
<to>Tulsi</to>
<from>Giri</from>
</note>
6. Comments in XML.
The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->
7. White-space is preserved in XML.
8. Avoid HTML tags.