Invalid documents don't follow the syntax rules defined by the XML specification. If a developer has defined rules for what the document can contain in a DTD or schema, and the document doesn't follow those rules, that document is invalid as well. (See Defining document content for a proper introduction to DTDs and schemas for XML documents.)
Valid documents follow both the XML syntax rules and the rules defined in their DTD or schema.
Well-formed documents follow the XML syntax rules but don't have a DTD or schema.
An XML document must be contained in a single element. That single element is called the root element, and it contains all the text and any other elements in the document. In the following example, the XML document is contained in a single element, the <greeting> element. Notice that the document has a comment that's outside the root element; that's perfectly legal.
Here's a document that doesn't contain a single root element:
//第2段
<?xml version="1.0"?>
<!-- An invalid document -->
<greeting>
Hello, World!
</greeting>
<greeting>
Hola, el Mundo!
</greeting>
An XML parser is required to reject this document, regardless of the information it might contain.
XML扫描器将会把第2段描述中的内容扔掉,因为它“违反了XML的规定”
Elements can't overlap(element的“非重叠性”)
Page 4 of 10
XML elements can't overlap. Here's some markup that isn't legal:
<!-- NOT legal XML markup -->
<p>
<b>I <i>really
love</b> XML.
</i>
</p>
If you begin a <i> element inside a <b> element, you have to end it there as well. If you want the text XML to appear in italics, you need to add a second <i> element to correct the markup: