The need for XML “schemas”

•Unlike any other data format, XML is totally flexible, elements can be nested in arbitrary ways
•We can start by writing the XML data -- no need for a priori design of a schema
–Think relational databases, or Java classes
•However, schemas are necessary:
–Facilitate the writing of applications that process data
–Constraint the data that is correct for a certain application
–Have a priori agreements between parties with respect to the data being exchanged
•Schema: a model of the data
–Structural definitions
–Type definitions
–Defaults
  • Introduction

DTD is the abbreviation for "Document Type Definition" to define the legal building blocks of   an XML document with a list of legal elements and attributes, which can be defined inline an XML doc or as an external reference. With the DTD, your can verify the data that you receive from the outside world is valid. Elements/attributes names in XML are case-sensitive, so DTD must be case-sensitive also!

Parsing XML Documents

•Parsers
–Validating
•Able to read DTD
•Determine whether XML document conforms to DTD 

– Valid document conforms to DTD

» Document is then well formed, by definition

» Documents can be well formed, but not valid

–Nonvalidating
•Able to read DTD
•Cannot check document against DTD for conformity
 

Example: inline example

<?xml version="1.0"?>  <? PI ?>

<!DOCTYPE note [                // defines that the root element of this document is note

<!ELEMENT note (to,from,heading,body)>  //defines that the note element contains four elements: "to,from,heading,body"

<!ELEMENT to (#PCDATA)>   // defines the to element to be of type "#PCDATA"

<!ELEMENT from (#PCDATA)>                                   Parsable character data

<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

<note>           Root element
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>

external example:

use <!DOCTYPE note SYSTEM "note.dtd"> to replace the inline DTD block

SYSTEM indicates its a private DTD (not for public distribution)

  • Building Block

Elements, Attributes, Entities, CDATA, PCDATA

PCDATA should not contain any characters like &, > or < which should be represented by &amp, &lt and &gt entities, respectively.

CDATA will not be parsed by a parser.

 

elements:

  1. Declaring Elements:<!ELEMENT element-name category>
  2. Empty elements: <!ELEMENT oven EMPTY>  <oven/>
  3. Elements with only parsed character data: <!ELEMENT from (#PCDATA)>
  4. can contain any combination of parable data: <!ELEMENT note ANY> replace by specific content now.
  5. Elements with one or more children: <!ELEMENT element-name (child1,child2,…)>
  6. Only one occurrence: <!ELEMENT element-name (child-name)>
  7. one or more occurrence: <!ELEMENT element-name (child-name+)>
  8. zero or more occurrence: <!ELEMENT element-name (child-name*)>
  9. zero or one occurrence: <!ELEMENT element-name (child-name?)>
  10. either or occurrence: <!ELEMENT note (to,from,header,(message|body))>
  11. mixed content: <!ELEMENT note (#PCDATA|to|from|header|message)*>

5:consecutively; 11: no specific sequence

attributes:

<!ATTLIST element-name attribute-name attribute-type attribute-value>

Declaration:     <!ATTLIST payment typeCDATA "check">

XML example:     <payment type="check" />

 

Types

Description

CDATA (strings)

The value is character data except <, >, &, ’and ”

(en1|en2|..)  enumerated

The value must be one from an enumerated list

ID tokenized most restrictive

The value is a unique id--> Uniquely identifies an element

IDREF tokenized

The value is the id of another element--> Point to element with ID

IDREFS tokenized

The value is a list of other ids  consistency to ID

NMTOKEN

The value is a valid XML name

NMTOKENS

The value is a list of valid XML names

ENTITY tokenized

The value is an entity

ENTITIES tokenized

The value is a list of entities

NOTATION

The value is a name of a notation

xml:

The value is a predefined xml value

 

value: the value of the attribute

 

Required:

<!ATTLIST person number CDATA #REQUIRED>

Valid XML:
<person number="5677" />

Invalid XML:
<person />

 

Implied:

<!ATTLIST contact fax CDATA #IMPLIED>

Valid XML:
<contact fax="555-667788" />

Valid XML:
<contact />

 

Fixed:

<!ATTLIST sender company CDATA #FIXED "Microsoft">

Valid XML:
<sender company="Microsoft" />

Invalid XML:
<sender company="W3Schools" />

 

Enumerated attribute values:

<!ATTLIST payment type (check|cash) "cash">

XML example:
<payment type="check" />
or
<payment type="cash" />

elements vs attributes:

There is no rule for when to use elements or attributes

Store data in element is better and use attribute to provide information not relevant to data.

Metadata (data about data) should be stored as attributes, and that data itself should be stored   as elements.

Entities:

internal entities: <!ENTITY entity-name "entity-value">

DTD Example:

<!ENTITY writer "Donald Duck.">

<!ENTITY copyright "Copyright W3Schools.">

XML example:

<author>&writer;&copyright;</author>

 

external entities:<!ENTITY entity-name SYSTEM "URI/URL">

DTD Example:

<!ENTITY writer SYSTEM "http://www.w3schools.com/entities.dtd">

<!ENTITY copyright SYSTEM "http://www.w3schools.com/entities.dtd">

XML example:

<author>&writer;&copyright;</author>

 
  • A General XML Validator - Errors in XML documents will stop your XML program. 

To help you check your xml files, you can syntax-check any XML file here.

 

Semantic Web

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

XML-->DTD&Schema Notes的更多相关文章

  1. JavaScripts学习日记——XML DTD Schema

    今日关键词: XML DTD Schema 1.XML 1 XML的概述 1.1 什么是XML XML全称为Extensible Markup Language,意思是可扩展的标记语言.XML语法上和 ...

  2. XML Dtd Schema

    在XML技术里,可以编写一个文档来约束一个XML文档的书写规范,这称之为XML约束. 整体比较: XML Schema符合XML语法结构. DOM.SAX等XML API很容易解析出XML Schem ...

  3. xml语法、DTD约束xml、Schema约束xml、DOM解析xml

    今日大纲 1.什么是xml.xml的作用 2.xml的语法 3.DTD约束xml 4.Schema约束xml 5.DOM解析xml 1.什么是xml.xml的作用 1.1.xml介绍 在前面学习的ht ...

  4. XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax

    本文主要涉及:xml概念描述,xml的约束文件,dtd,xsd文件的定义使用,如何在xml中引用xsd文件,如何使用java解析xml,解析xml方式dom sax,dom4j解析xml文件 XML来 ...

  5. XML DTD跟SCHEMA约束 语法了解

    dtd语法 元素: <!Element 元素名称 数据类型|包含内容> 数据类型: #PCDATA:普通文本 使用的时候一般用()引起来 包含内容: 该元素下可以出现哪些元素, 用()引起 ...

  6. Eclipse引入自定义XML约束文件(DTD,SCHEMA)问题

    Eclipse引入自定义XML约束文件(DTD,SCHEMA)问题 1:说明 使用Eclipse 编写xml文件的约束文件的,包括DTD约束文件,Schema约束文件的时候, 我们也需要接受eclip ...

  7. XML约束——Schema约束

    XML Schema 也是一种用于定义和描述 XML 文档结构与内容的模式语言,其出现是为了克服 DTD 的局限性 XML Schema VS DTD: •XML Schema符合XML语法结构. • ...

  8. XML的Schema约束

    XSD文档至少要包含:schema根元素和XML模式命名空间的定义.元素定义.需要注意的是XSD中必须定义一个且只能定义一个schema根元素,根元素中包括模式的约束,XML模式命名空间的定义,其他命 ...

  9. XML和Schema

    2017-11-03 19:33:56 XML:Extensible Markup Language,也就是可扩展标记语言.XML工具使处理和转化信息变得十分容易和方便. XML和HTML格式是古老的 ...

  10. XML——DTD

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

随机推荐

  1. 洛谷P1328 生活大爆炸版石头剪刀布——S.B.S.

    题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...

  2. Fast RCNN 训练自己数据集 (2修改数据读取接口)

    Fast RCNN训练自己的数据集 (2修改读写接口) 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ http ...

  3. [No00006B]方便的网络下载工具wget 可下载网站目录下的所有文件(可下载整个网站)

    wget是linux下命令行的下载工具,功能很强大,它能完成某些下载软件所不能做的,比如如果你想下载一个网页目录下的所有文件,如何做呢?网络用户有时候会遇到需要下载一批文件的情况,有时甚至需要把整个网 ...

  4. sql 首写字母查询姓名(字段)

    来自网上大神,不知道是谁,挂不上链接 /////////////////////// 1.生成方法函数 create function f_GetPy(@str nvarchar(4000)) ret ...

  5. MAC下搭建及使用XAMPP的详细教程

    Windows和Linux都可以搭建本地伺服器(LAMP和IIS),Mac當然也可以,下面教你怎麼使用XAMPP在Mac下搭建一個功能齊全的本地伺服器 所需條件 1.Mac系統(廢話) 2.最好有可用 ...

  6. PyQt4入门

    PyQt4入门教程(6)_对话框 文中译者的话将用方括号[]标出.对话框(Dialogs)是现代GUI程序中不可缺少的一部分.对话本来指的是两个或者更多人之间的交流,而在计算机应用中,对话是一个可以让 ...

  7. 原创jquery插件treeTable(转)

    由于工作需要,要直观的看到某个业务是由那些子业务引起的异常,所以我需要用树表的方式来展现各个层次的数据. 需求: 1.数据层次分明: 2.数据读取慢.需要动态加载孩子节点: 3.支持默认展开多少层. ...

  8. 2016-2017-2 《Java程序设计》预备作业2总结

    2016-2017-2 <Java程序设计>预备作业2总结 古希腊学者普罗塔戈说过:「头脑不是一个要被填满的容器,而是一束需要被点燃的火把.」 在对计算机系的学生情况的调查中,我说: 最近 ...

  9. 大流量网站性能优化:一步一步打造一个适合自己的BigRender插件

    BigRender 当一个网站越来越庞大,加载速度越来越慢的时候,开发者们不得不对其进行优化,谁愿意访问一个需要等待 10 秒,20 秒才能出现的网页呢? 常见的也是相对简单易行的一个优化方案是 图片 ...

  10. C#进阶系列——MEF实现设计上的“松耦合”(终结篇:面向接口编程)

    序:忙碌多事的八月带着些许的倦意早已步入尾声,金秋九月承载着抗战胜利70周年的喜庆扑面而来.没来得及任何准备,似乎也不需要任何准备,因为生活不需要太多将来时.每天忙着上班.加班.白加班,忘了去愤,忘了 ...