XML Document Types
An XML document with correct syntax is called "Well Formed".
A "Valid" XML document must also conform to a specified document type.
Well Formed XML Documents
An XML document with correct syntax is "Well Formed".
The syntax rules were described in the previous chapters:
- XML documents must have a root element
- XML elements must have a closing tag
- XML tags are case sensitive
- XML elements must be properly nested
- XML attribute values must be quoted
<body>Don't forget me this weekend!</body>
An XML Validator
To help you check the syntax of your XML files, we have created an XML validator to syntax-check your XML.
Please see the next chapter.
Valid XML Documents
A valid XML document is not the same as a well formed XML document.
The first rule, for a valid XML document, is that it must be well formed (see previous paragraph).
The second rule is that a valid XML document must conform to a document type.
Rules that defines legal elements and attributes for XML documents are often called document definitions, or document schemas.
When to Use a Document Definition?
A document definition is the easiest way to provide a reference to the legal elements and attributes of a document.
A document definition also provides a common reference that many users (developers) can share.
A document definition provides a standardization that makes life easier.
When NOT to Use a Document Definition?
XML does not require a document definition.
When you are experimenting with XML, or when you are working with small XML files, creating document definitions may be a waste of time.
If you develop applications, wait until the specification is stable before you add a document definition. Otherwise, your software might stop working because of validation errors.
There are different types of document definitions that can be used with XML:
- The original Document Type Definition (DTD)
- The newer, and XML based, XML Schema
Thank You For Helping Us!
Your message has been sent to W3Schools.