XML-->DTD&Schema Notes
The need for XML “schemas”
- 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
– Valid document conforms to DTD
» Document is then well formed, by definition
» Documents can be well formed, but not valid
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 &, < and > entities, respectively.
CDATA will not be parsed by a parser.
elements:
- Declaring Elements:<!ELEMENT element-name category>
- Empty elements: <!ELEMENT oven EMPTY> <oven/>
- Elements with only parsed character data: <!ELEMENT from (#PCDATA)>
- can contain any combination of parable data: <!ELEMENT note ANY> replace by specific content now.
- Elements with one or more children: <!ELEMENT element-name (child1,child2,…)>
- Only one occurrence: <!ELEMENT element-name (child-name)>
- one or more occurrence: <!ELEMENT element-name (child-name+)>
- zero or more occurrence: <!ELEMENT element-name (child-name*)>
- zero or one occurrence: <!ELEMENT element-name (child-name?)>
- either or occurrence: <!ELEMENT note (to,from,header,(message|body))>
- 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;©right;</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;©right;</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的更多相关文章
- JavaScripts学习日记——XML DTD Schema
今日关键词: XML DTD Schema 1.XML 1 XML的概述 1.1 什么是XML XML全称为Extensible Markup Language,意思是可扩展的标记语言.XML语法上和 ...
- XML Dtd Schema
在XML技术里,可以编写一个文档来约束一个XML文档的书写规范,这称之为XML约束. 整体比较: XML Schema符合XML语法结构. DOM.SAX等XML API很容易解析出XML Schem ...
- 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 ...
- 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来 ...
- XML DTD跟SCHEMA约束 语法了解
dtd语法 元素: <!Element 元素名称 数据类型|包含内容> 数据类型: #PCDATA:普通文本 使用的时候一般用()引起来 包含内容: 该元素下可以出现哪些元素, 用()引起 ...
- Eclipse引入自定义XML约束文件(DTD,SCHEMA)问题
Eclipse引入自定义XML约束文件(DTD,SCHEMA)问题 1:说明 使用Eclipse 编写xml文件的约束文件的,包括DTD约束文件,Schema约束文件的时候, 我们也需要接受eclip ...
- XML约束——Schema约束
XML Schema 也是一种用于定义和描述 XML 文档结构与内容的模式语言,其出现是为了克服 DTD 的局限性 XML Schema VS DTD: •XML Schema符合XML语法结构. • ...
- XML的Schema约束
XSD文档至少要包含:schema根元素和XML模式命名空间的定义.元素定义.需要注意的是XSD中必须定义一个且只能定义一个schema根元素,根元素中包括模式的约束,XML模式命名空间的定义,其他命 ...
- XML和Schema
2017-11-03 19:33:56 XML:Extensible Markup Language,也就是可扩展标记语言.XML工具使处理和转化信息变得十分容易和方便. XML和HTML格式是古老的 ...
- XML——DTD
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
随机推荐
- Windows 10 装机回忆录
Frank.Han 标记: Windows,快捷键,安装 2015年10月我便更新了Win10系统,一直用着很顺手,比起Win8.x,他更像Win7的嫡系版本. 屏蔽掉系统自带的平板服务(小娜.地理位 ...
- NOIP2013pj车站分级[拓扑排序]
题目描述 一条单向的铁路线上,依次有编号为 1, 2, …, n 的 n 个火车站.每个火车站都有一个级 别,最低为 1 级.现有若干趟车次在这条线路上行驶,每一趟都满足如下要求:如果这趟车 次停靠了 ...
- jQuery与Struts2综合应用[stream/json]
一.使用stream类型的Result实现Ajax 具体步骤: ① 定义InputStream类型的成员变量及getter和setter ②具体业务方法中将要发送到客户端的json字符串赋值给成员变量 ...
- [No000089]String的(补空位)左对齐,(补空位)右对齐
using System; namespace Chinese中文排序Sort { internal class Program { /// <summary> /// 取子字符串 /// ...
- Using Internal EEPROM of PIC Microcontroller
There are commonly three types of memories in a PIC Microcontroller, Flash Program Memory, Data Memo ...
- JAVA的垃圾回收机制
1. 垃圾回收的意义 在C++中,对象所占的内存在程序结束运行之前一直被占用,在明确释放之前不能分配给其它对象:而在Java中,当没有对象引用指向原先分配给某个对象的内存时,该内存便成为垃圾.JVM的 ...
- 一些有用的configue参数
--prefix 指定文件被安装到文件系统中的目录名.例:--prefix=/usr/local/apache --enable-layout 该选项允许你选择一个预先定义好的文件系统结构,也就是可以 ...
- IE下a标签后面的span元素向右浮动后错位
错误原因span放在了a标签之后 正确写法是放在之前 如下: <li><span>2016-07-29</span><a href="#" ...
- 关于Deprecated: mysql_result: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
require_once('connect.php'); $sql = "select * from introduce"; \(query = mysql_query(\)sql ...
- offsetHeight, clientHeight与scrollHeight的区别
在网上搜了一下,结论非常笼统,讲IE从不讲版本,因此自己做了测试并上传结论.以下结论皆是在标准模式下测试通过的,没有测试quirk模式. clientHeight 大部分浏览器对 clientHe ...