- Rule 1: All XML Must Have a Root Element
- Rule 2: All Tags Must Be Closed
- Rule 3: All Tags Must Be Properly Nested
- Rule 4: Tag Names Have Strict Limits
- Rule 5: Tag Names Are Case Sensitive
- Rule 6: Tag Names Cannot Contain Spaces
- Rule 7: Attribute Values Must Appear Within Quotes
- Rule 8: White Space Is Preserved
- Rule 9: Avoid HTML Tags (Optional)
Rule 2: All Tags Must Be Closed
When a tag is declared (opened), it must also be closed. Any unclosed tags will break the code. Even tags that don’t need to be closed in HTML must be closed in XML or XHTML. To open a tag, type the name of the element between less-than (<) and greater-than (>) characters, like this opening tag:
<author>
To close a tag, repeat the opening tag exactly, but insert a slash in front of the tag name, like this closing tag:
</author>
Even empty tags, such as <hr> and <br>, must be closed.
Wrong:
<author>Ernest Hemingway <p>Roses are Red <hr>
Right:
<author>Ernest Hemingway</author> <p>Roses are Red</p> <hr></> <hr />