XML Syntax Rules

You must refer to and implement the following 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

When you are creating XML syntax, make sure that you use the 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 does not impact 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.

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

Attribute values must always be quoted

Make sure that you use 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.