XML Syntax Rules

You must follow these rules when you create XML syntax:

  • All XML elements must have a closing tag.
  • XML tags are case sensitive.
  • All XML elements must be properly nested.
  • All XML documents must have a root element.
  • Attribute values must always be quoted.

All XML elements must have a closing tag

It is illegal to omit the closing tag when you are creating XML syntax. XML elements must have a closing tag.

Incorrect:

<body>See Spot run.
<body>See Spot catch the ball.

Correct:

<body>See Spot run.</body>
<body>See Spot catch the ball.</body>

XML tags are case sensitive

When you create XML documents, the tag <Body> is different from the tag <body>.

Incorrect:

<Body>See Spot run.</body>

Correct:

<body>See Spot run.</body>

All XML elements must be properly nested

Improper nesting of tags makes no sense to XML.

Incorrect:

<b><i>This text is bold and italic.</b></i>

Correct:

<b><i>This text is bold and italic.</i></b>

All 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 within this root element. All elements can have sub elements (child elements). Sub elements must be correctly nested within their parent element.

Example:

<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>

Attribute values must always be quoted

It is illegal to omit quotation marks around attribute values. XML elements can have attributes in name/value pairs; however, the attribute value must always be quoted.

Incorrect:

<?xml version= “1.0” encoding=“ISO-8859-1”?>
<note date=05/05/05>
<to>Dick</to>
<from>Jane</from>
</note>

Correct:

<?xml version= “1.0” encoding=“ISO-8859-1”?>
<note date=”05/05/05”>
<to>Dick</to>
<from>Jane</from>
</note>

In the incorrect document, the date attribute in the note element is not quoted.