XML Syntax
Unit - II
Web Technologies
XML Documents Must Have a Root Element
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML Documents Must Have a Root Element
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The XML Prolog
<?xml version="1.0" encoding="UTF-8"?>
This must come first in the document.
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
XML Tags are Case Sensitive
XML Elements Must be Properly Nested
In HTML
<b><i>This text is bold and italic</b></i>
In XML, all elements must be properly nested within each other:
<b><i>This text is bold and italic</i></b>
XML Attribute Values Must Always be Quoted
XML elements can have attributes in name/value pairs just like in HTML.
In XML, the attribute values must always be quoted:
<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
Entity References
<message>salary < 1000</message>
<message>salary < 1000</message>
Comments in XML
The syntax for writing comments in XML is similar to that of HTML:
<!-- This is a comment -->
Two dashes in the middle of a comment are not allowed:
<!-- This is an invalid -- comment -->
White-space is Preserved in XML
XML does not truncate multiple white-spaces (HTML truncates multiple white-spaces to one single white-space):
XML: Hello Tove
HTML: Hello Tove