XML Design
- DTD
1. 不能定义如下的element
<book>的<heading>必须有<title>和<author>
<chapter>的<heading>必须有<title>
2. 没有继承
3. 不能定义一个filed验证语法
<zipcode>xx</zipcode>xxx只能是5位数字
4. 不是xml Format, so 不能被标准的xml解析器解析
- 如何关联一个DTD
<!DOCTYPE slideshow SYSTEM "slideshow1a.dtd">
- Attribute 还是 Element ?
Forced choises
1. The data contains substructures
Chose ELEMENT
2. The data contains multiple lines
Chose ELEMENT
For example:
<company>
<supplier>s1</supplier>
<supplier>s2</supplier>
</company>
3. the data changes frequently
Chose ELEMENT
Because for editor, it's easier for modifing element than attribute
4. the data is confined to a small number of fixed choices
Chose ATTRIBUTE
因为DTD可以定义一个attribute的取值范围,但是对ELEMENT无效
有些editor可以根据DTD对attribute的取值范围定义生成下拉列表
Stylistic Choices
1. Visiability
如果信息需要被显示,则选择Element;否则选择attribute
例如:Order-Entry中的Shoe,shoe-size应该定义为Element,
而supplier-id应该定义为attribute
2. Consumer / Provider
如果是由GUI录入的,通常使用Element
3. Container vs. Contents
把Element看作是Container,Container的Content ( water or milk) 使用Element
Container的特征(red or blue)使用attribute
综合例子:
Slidshow:
- Type (executive, technical) of it is best modeled as an ATTRIBUTE
- Title of it ispart of its content, should be modeled as an ELEMENT
- Type is not shown,
Title is shown when slide is displayed