XML Design

博客围绕XML设计展开,介绍了DTD的局限性,如不能定义特定元素、无继承、无法定义字段验证语法且非XML格式。还说明了关联DTD的方法,以及在不同场景下选择Attribute还是Element的依据,包括数据结构、修改频率、显示需求等,并给出了综合示例。

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值