xml validation(二)

本文介绍 XML 文档类型定义 (DTD) 的基本概念及其验证过程。详细解释了 DTD 的不同形式,包括外部 DTD 和内部 DTD 的结构与使用方法。此外,还探讨了元素定义语法和修饰符等关键概念。

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

<!-- /* Font Definitions */ @font-face {font-family:Courier; panose-1:2 7 4 9 2 2 5 2 4 4; mso-font-alt:"Courier New"; mso-font-charset:0; mso-generic-font-family:modern; mso-font-format:other; mso-font-pitch:fixed; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体;} @page Section1 {size:595.3pt 841.9pt; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->

Section 3. Validating a document

 

Xml document will be parsed as a DOM document or a SAX stream. (What is DOM and SAX stream? We will tell it later)

The parse will also check the structure of document against DTD or schema if it has been configured to do so. It also will create error handler.

--Error Handler will look for it later.

 

Section 4. DTD(Document Type Definition)

 

External DTDs

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

--<!DOCTYPE : tell the processor it is DOCTYPE declaration.

--html: indicates that the name of the root element for the document. If the document started anything but <html>, it would immediately be deemed invalid.

--PUBLIC : designate a publicly recognized DTD, potentially saving the processor a trip to the server to retrieve it. (What’s meaning?) Other option is SYSTEM.

-- -//W3C//DTD HTML 4.01 Transitional//EN: The actual public identifier for the Transitional XHTML DTD.

 

For custom DTDs, developers typically use a SYSTEM identifier, such as:

<!DOCTYPE memories SYSTEM "http://www.nicholaschase.com/memories.dtd">

 

Structure of an internal DTD

 

 

 

Variable element content

With a pipe character (|), meaning the data structure contains an element named location that may contain either a place element or a description element. With a pipe character(|) for choicing.

<!ELEMENT location (place | description) >

 

Modifiers (*, +, and ?)

--*: means an element can appear 0 or more times

--+: means an element can appear 1 or more times.

--?: means an element can appear 0 or 1 time.

 

For example:

<!DOCTYPE memories[

    <!ELEMENT memories (memory*)>           --memories can have 0 or more memory

    <!ELEMENT memory (media,

                                           subdate,

                                           donor?,     --0 or 1 donor

                                           subject+,   --1 or more subject

                                           location)>

    <!ELEMENT subdate (#PCDATA)>

    <!ELEMENT donor (#PCDATA)>

    <!ELEMENT subject (#PCDATA)>

    <!ELEMENT location (place |

                                           description)>

    <!ELEMENT description (#PCDATA)>

    <!ELEMENT place (#PCDATA)>

    <!ELEMENT media EMPTY>

]>

 

“?” means 0 or 1. But cannot insert donor element in memory parent. (WHY?)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值