我 question开了这个问题,但我不清楚XML的图象和DTD(文件类型定义)是什么,以及为什么XML的表象比DTD更为强大。
任何指导都将受到高度赞赏。
我 question开了这个问题,但我不清楚XML的图象和DTD(文件类型定义)是什么,以及为什么XML的表象比DTD更为强大。
任何指导都将受到高度赞赏。
http://www.informit.com/articles/article.aspx?p=24614&seqNum=3: rel=“noreferer” Diss between DTDs and Schema section of the Converting a DTD into a Schema 条款:
The critical difference between DTDs and XML Schema is that XML Schema utilize an XML-based syntax, whereas DTDs have a unique syntax held over from SGML DTDs. Although DTDs are often criticized because of this need to learn a new syntax, the syntax itself is quite terse. The opposite is true for XML Schema, which are verbose, but also make use of tags and XML so that authors of XML should find the syntax of XML Schema less intimidating.
The goal of DTDs was to retain a level of compatibility with SGML for applications that might want to convert SGML DTDs into XML DTDs. However, in keeping with one of the goals of XML, "terseness in XML markup is of minimal importance," there is no real concern with keeping the syntax brief.
[......]
因此,当我们皈依性传播疾病时,其他一些可能特别重要的差异是什么? 让我们看一看。
<><>Typing
DTDs和XML Schema之间最重要的区别是,在Schema与要素和属性声明一起创建和使用数据类型的能力。 事实上,XML Schema建议的一半用于数据搭配和XML Schema,这产生了如此重要的差别。 我们详细介绍了本书第三部分“XML Schema数据类型”中的数据类型。
[......]
<>可见>
DTDs和Schema差别很大的另一个领域是出现限制。 如果你回顾一下我们在第2章“结构”中以前的例子(或你本人与TDD公司合作),那么你可以用三种符号来限制某一要素的发生次数:*、+和?
[......]
<>0>
因此,我要说的是,我们有了一个因素,我们希望能够确定锡土的大小特征,使用户能够选择一个大小:小、中或大的大小。 我们的残疾人发展基金会希望:
<!ELEMENT item (shirt)> <!ELEMENT shirt (#PCDATA)> <!ATTLIST shirt size_value (small | medium | large)>
[......]
但是,如果我们希望<条码>将条码>变成一个要素? 我们能够用DVD来做到这一点。 DTDs没有规定在内容内容中进行列举。 然而,由于与Schema的数据类型,当我们宣布了前一个例子中的列举时,我们实际上创建了一个名为“<条码>的<传真/<代码>的<代码>。 我们现在可以用一个要素:
<xs:element name="size" type="size_value">
[......]
XML Schema定义与文件类型定义之间的差别包括:
并非所有这些子弹点都是100%的准确点,但你们都获得了光顾。
另一方面:
正如许多人以前提到的那样,XML Schema利用以XML为基础的辛塔和DTDs有一个独特的辛迪加。 DTD并不支持数据类型,这确实很重要。
让我们看到一个非常简单的例子,即大学有多个学生,每个学生有两个要素“名称”和“年”。 请注意,我在守则中仅作评论就使用了“/->”;
现在,我将在发司和社发司写这一榜样。
<><>DTD
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE university[ // --> university as root element
<!ELEMENT university (student*)> // --> university has * = Multiple students
<!ELEMENT student (name,year)> // --> Student has elements name and year
<!ELEMENT name (#PCDATA)> // --> name as Parsed character data
<!ELEMENT year (#PCDATA)> // --> year as Parsed character data
]>
<university>
<student>
<name>
John Niel //---> I can also use an Integer,not good
</name>
<year>
2000 //---> I can also use a string,not good
</year>
</student>
</university>
<XML Schema定义(XSD)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name ="uniType"> //--> complex datatype uniType
<xsd:sequence>
<xsd:element ref="student" maxOccurs="unbounded"/> //--> has unbounded no.of students
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="stuType"> //--> complex datatype stuType
<xsd:sequence>
<xsd:element ref="name"/> //--> has element name
<xsd:element ref="year"/> //--> has element year
</xsd:sequence>
</xsd:complexType>
<xsd:element name="university" type="uniType"/> //--> university of type UniType
<xsd:element name="student" type="stuType"/> //--> student of type stuType
<xsd:element name="name" type="xsd:string"/> //--> name of datatype string
<xsd:element name="year" type="xsd:integer"/> //--> year of datatype integer
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<university>
<student>
<name>
John Niel
</name>
<year>
2000 //--> only an Integer value is allowed
</year>
</student>
</university>
DTD预设XML,因此不具有XML的效力。 这很可能是XSD发明的最大原因。
both specify elements, attributes, nesting, ordering, #occurences
XSD also has data types, (typed) pointers, namespaces, keys and more.... unlike DTD
此外,虽然科学、技术和科学部的辛勤工作很少,但XML是延伸的,因此可以迅速学习。
一种不同之处是,在DVD中,某一要素的内容模式完全由其名称决定,而不论该文件中的内容如何:
假设你想要
person
elementname
name
itself has child elements first
and last
. 和
<person>
<name>
<first></first>
<last></last>
</name>
</person>
如果同一文件中的<条码>、条码>要素也需要有儿童要素名称,则DTD要求这一名称要素也必须有儿童要素<条码>、第1条代码>和<条码>。 尽管city.name
并不要求first
和last
作为儿童。
相比之下,XML Schema允许你在当地宣布儿童元素类型;你可以分别宣布<> 姓名/编码> 和<代码> 姓名/编码> 和<> 姓名/编码> 。 因此,在这些情况下给他们适当的内容模式。
另一个重大差异是支持名称空间。 由于DTDs是最初的XML规格的一部分(和从SGML中继承),因此,由于XML名称空间后来被具体指明,因此它们根本不使用名称。 你们可以结合名称空间使用DVD,但需要一些胁迫,如被迫界定性病的预设点,只使用这些预设物,而不是使用任意的预设物。
对我来说,其他差异大多是表面的。 数据类型的支持可以很容易地添加到DTDs上,而Syntax只是yn。 (一) 发现XML Schema syntax horrible,并且永远不想交出XML Schema,我想说这句话是关于DTDs或RELAX NG的chem;如果我需要XML Schema,出于某种原因,我通常写的是RELAX NG,并将之改成<>trang>/code>。)
<>Similarities
DTDs和Schemas都履行同样的基本职能:
<>Differences:
用于文本密集型应用的技术性影响比较好,而表象在数据密集型工作流程方面有若干优势。
Schemas是用XML书写的,因此遵循同样的规则,而DTDs是用完全不同的语言书写的。
<>>Examples:
DTD:
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT employees (Efirstname, Elastname, Etitle, Ephone, Eemail)>
<!ELEMENT Efirstname (#PCDATA)>
<!ELEMENT Elastname (#PCDATA)>
<!ELEMENT Etitle (#PCDATA)>
<!ELEMENT Ephone (#PCDATA)>
<!ELEMENT Eemail (#PCDATA)>
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:od="urn:schemas-microsoft-com:officedata">
<xsd:element name="dataroot">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="employees" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="generated" type="xsd:dateTime"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="employees">
<xsd:annotation>
<xsd:appinfo>
<od:index index-name="PrimaryKey" index-key="Employeeid " primary="yes"
unique="yes" clustered="no"/>
<od:index index-name="Employeeid" index-key="Employeeid " primary="no" unique="no"
clustered="no"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Elastname" minOccurs="0" od:jetType="text"
od:sqlSType="nvarchar">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Etitle" minOccurs="0" od:jetType="text" od:sqlSType="nvarchar">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Ephone" minOccurs="0" od:jetType="text"
od:sqlSType="nvarchar">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Eemail" minOccurs="0" od:jetType="text"
od:sqlSType="nvarchar">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Ephoto" minOccurs="0" od:jetType="text"
od:sqlSType="nvarchar">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<>DTD的目的是界定XML文件的结构。 该法律界定了法律要素清单的结构:
<!ATTLIST contact type CDATA #IMPLIED>
<!ELEMENT address1 ( #PCDATA)>
<!ELEMENT city ( #PCDATA)>
<!ELEMENT state ( #PCDATA)>
<!ELEMENT zip ( #PCDATA)>
XML Schema enables schema authors to specify that element quantity’s data must
be numeric or, even more specifically, an integer. In the following example I used string
:
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="address1" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="state" type="xs:string"/>
<xs:element name="zip" type="xs:string"/>
</xs:sequence>
</xs:complexType>
DTD只能有两种类型的数据:CDATA和PCDATA。 但是,在图表中,你可以使用你在编制方案时所用的所有原始数据类型,而且你可以灵活地界定自己的习惯数据类型。
开发商根据核心数据类型,使用不同的操作者和变压器,可以生成定制数据类型。
当XML首次出来时,我们被告知它将解决我们的所有问题: XML将是方便用户的,可以肯定地挖掘,避免强硬,不需要任何方案拟订技能。 我学习了DVD,并写了我自己的XML教区。 15年之后,我看到,大多数XML不便于使用,而且不十分合理(取决于其使用)。 一旦一些cl子把XML打到一个数据库,我就知道数据类型是完全不可避免的。 而且,你应当看到,我不得不在另一天工作。 如果是这样,我不知道什么! 现在,看到与XML数据或接口相关的各类问题都变得不寻常。 我热爱XML,但远未达到其最初的入侵起点。
答案是否简短? 由于科学、科学、技术和革新司允许你更精确地界定XML结构,因此DTDs被贬为XSD。
DTD被大量折旧,因为它作为化物语言的效用有限,没有支持名称空间,也没有支持数据类型。 此外,DTD syntax非常复杂,难以理解和维持。