1 of 12

XML Syntax

Unit - II

Web Technologies

2 of 12

  • XML Syntax Rules
  • XML Documents Must Have a Root Element
  • The XML Prolog
  • All XML Elements Must Have a Closing Tag
  • XML Tags are Case Sensitive
  • XML Elements Must be Properly Nested
  • XML Attribute Values Must Always be Quoted
  • Entity References
  • Comments in XML
  • White-space is Preserved in XML
  • Well Formed XML - XML documents that conform to the syntax rules above are said to be "Well Formed" XML documents.

3 of 12

XML Documents Must Have a Root Element

<root>

<child>

<subchild>.....</subchild>

</child>

</root>

4 of 12

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>

5 of 12

The XML Prolog

<?xml version="1.0" encoding="UTF-8"?>

This must come first in the document.

6 of 12

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

7 of 12

XML Tags are Case Sensitive

  • 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

8 of 12

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>

9 of 12

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>

10 of 12

Entity References

<message>salary < 1000</message>

<message>salary &lt; 1000</message>

11 of 12

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 -->

12 of 12

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