Well-Formed XML

本文介绍了XML文档的基本规范,包括文档必须具有一致且定义明确的结构、所有属性值需引用、空白字符的重要性、开始标签与结束标签的对应关系等。要使文档有效,除了遵循这些基本规范外,还需符合DTD或XML Schema的约束。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In this section, we explain the various syntactical rules of XML. Documents that follow these rules are called well-formed, but not necessarily valid, as we'll see. If your document breaks any of these rules, it will be rejected by most, if not all, XML parsers.

Well-Formedness

The minimal requirement for an XML document is that it be well-formed, meaning that it adheres to a small number of syntax rules, which are summarized in Table 3-1 and explained in the following sections. However, a document can abide by all these rules and still be invalid. To be valid, a document must both be well-formed and adhere to the constraints imposed by a DTD or XML Schema.

  • Table 3.1 XML Syntax Rules (Well-Formedness Constraints)
  • The document must have a consistent, well-defined structure.
  • All attribute values must be quoted (single or double quotes).
  • White space in content, including line breaks, is significant.
  • All start tags must have corresponding end tags (exception: empty elements).
  • The root element must contain all others, which must nest properly by start/end tag pairing.
  • Elements must not overlap; they may be nested, however. (This is also technically true for HTML. Browsers ignore overlapping in HTML, but not in XML.)
  • Each element except the root element must have exactly one parent element that contains it.
  • Element and attribute names are case-sensitive: Price and PRICE are different elements.
  • Keywords such as DOCTYPE and ENTITY must always appear in uppercase; similarly for other DTD keywords such as ELEMENT and ATTLIST.
  • Tags without content are called empty elements and must end in "/>".
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值