收录查询

IBM网站上给出的XML的介绍(2)不完全摘录

Invalid, valid, and well-formed documents Page 2 of 10


There are three kinds of XML documents:

  • 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.

(1)无效文档
       如果文档中包含了DTD(文档类型定义)或Schema -----却没有按照DTD(文档类型定义)或Schema 的约定来做,则这样的文档依然是“无效文档”=======并不是只有那些没有按照XML规范来做的才属于“无效文档”的范畴。

(2)有效文档
取上面(1)中的--------反相并集。

(3)良好风格的文档
只使用XML约定来做,不使用DTD和Schema================好象并不实用,现在的一些工具都不是这样做的。

                            ****使用XML的相关工具来做-------(2)实践性比较强*****

The root element (element的“单根性”) Page 3 of 10


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.

//下面是---第1段XML文档内容
<?xml version="1.0"?>
<!-- A well-formed document -->          //完全合法的注释
<greeting>
  Hello, World!
</greeting>
          

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:


<!-- legal XML markup -->
<p>
  <b>I <i>really 
  love</i></b>
  <i>XML.</i>
</p>
          

An XML parser will accept only this markup; the HTML parsers in most Web browsers will accept both.


posted @ 2005-07-07 15:31  ->  阅读(259)  评论(0)    收藏  举报