XML 스키마와 DTD의 차이점은 무엇입니까?
나는이 질문을 봤지만 XML 스키마와 DTD (문서 유형 정의)가 무엇이며 XML 스키마가 DTD에 비해 더 강력한 이유를 명확하게 이해하지 못합니다.
모든 지침은 높이 평가 될 것입니다.
DTD를 스키마 기사 로 변환의 DTD 와 스키마 의 차이점 섹션에서 :
DTD와 XML 스키마의 중요한 차이점은 XML 스키마는 XML 기반 구문을 사용하는 반면 DTD는 SGML DTD에서 고유 한 구문을 유지한다는 것입니다. DTD는 새로운 구문을 배울 필요가 있기 때문에 종종 비난을 받지만 구문 자체는 매우 간결합니다. XML 스키마의 경우는 정반대이지만 자세한 내용은 태그와 XML을 사용하므로 XML 작성자는 XML 스키마 구문이 덜 협박해야합니다.
DTD의 목표는 SGML DTD를 XML DTD로 변환하려는 응용 프로그램에 대해 SGML과의 호환성 수준을 유지하는 것이 었습니다. 그러나 XML의 목표 중 하나를 유지하면서 "XML 마크 업의 중요성은 최소로 중요합니다"라는 구문을 간결하게 유지하는 데는 전혀 관심이 없습니다.
[...]
DTD를 변환 할 때 특히 중요한 다른 차이점은 무엇입니까? 한 번 보자.
타자
DTD와 XML 스키마의 가장 큰 차이점은 요소 및 속성 선언과 함께 스키마에서 데이터 유형을 작성하고 사용하는 기능입니다. 실제로 XML 스키마 권장 사항의 절반이 데이터 형식 및 XML 스키마에 전념한다는 것은 중요한 차이점입니다. 이 책의 Part III, "XML Schema Datatypes"에서 데이터 유형에 대해 자세히 다룹니다.
[...]
발생 제약
DTD와 스키마가 크게 다른 또 다른 영역은 발생 제한입니다. 2 장 "스키마 구조"(또는 DTD 관련 작업)의 이전 예를 기억할 경우 요소 발생 횟수를 제한하는 데 사용할 수있는 세 가지 기호가 있습니다. *, + 및?
[...]
열거
따라서 요소가 있고 셔츠의 크기 속성을 정의하여 사용자가 작은, 중간 또는 큰 크기를 선택할 수 있기를 원한다고 가정 해 봅시다. 우리의 DTD는 다음과 같습니다.
<!ELEMENT item (shirt)> <!ELEMENT shirt (#PCDATA)> <!ATTLIST shirt size_value (small | medium | large)>
[...]
그러나 우리가
size
요소 가되고 싶다면 어떻게해야 할까요? DTD로는 그렇게 할 수 없습니다. DTD는 요소의 텍스트 내용에 열거를 제공하지 않습니다. 그러나 스키마가있는 데이터 유형으로 인해 앞의 예제에서 열거를 선언 할 때 실제로 요소와 함께 사용할 수 있는simpleType
호출size_values
을 작성했습니다 .<xs:element name="size" type="size_value">
[...]
XSD (XML Schema Definition)와 DTD (Document Type Definition)의 차이점은 다음과 같습니다.
- XML 스키마는 XML로 작성되고 DTD는 SGML 구문에서 파생됩니다.
- XML 스키마는 요소 및 속성에 대한 데이터 유형을 정의하지만 DTD는 데이터 유형을 지원하지 않습니다.
- XML 스키마는 네임 스페이스를 지원하지만 DTD는 지원하지 않습니다.
- XML 스키마는 자식 요소의 수와 순서를 정의하지만 DTD는 정의하지 않습니다.
- XML 스키마는 XML DOM으로 직접 조작 할 수 있지만 DTD의 경우에는 불가능합니다.
- XML 스키마를 사용하는 사용자는 새로운 언어를 배울 필요는 없지만 DTD 작업은 사용자에게 어렵습니다.
- XML 스키마는 안전한 데이터 통신을 제공합니다. 즉, 발신자가 수신자가 이해할 수있는 방식으로 데이터를 설명 할 수 있지만 DTD 데이터의 경우 수신자가 오해 할 수 있습니다.
- XML 스키마는 확장 가능하지만 DTD는 확장 할 수 없습니다.
업데이트 : 2015.08.26
이 글 머리 기호가 모두 100 % 정확하지는 않지만 요점을 알 수 있습니다.
반면에 :
- DTD를 사용하면 XML 파일에 사용할 새 ENTITY 값을 정의 할 수 있습니다 .
- DTD를 사용하면 개별 XML 파일로 로컬로 확장 할 수 있습니다.
많은 사람들이 이전에 언급했듯이 XML 스키마는 XML 기반 구문을 사용하고 DTD는 고유 한 구문을 갖습니다. DTD는 중요한 데이터 유형을 지원하지 않습니다.
대학에 여러 명의 학생이 있고 각 학생마다 "이름"과 "연도"라는 두 가지 요소가있는 매우 간단한 예를 살펴 보겠습니다. 주석에는 코드에서 "//->"를 사용하고 있습니다.
이제이 예제를 DTD와 XSD로 작성하겠습니다.
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 스키마 정의 (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가 발명 된 가장 큰 이유 일 것입니다.
XSD와 DTD의 유사점
both specify elements, attributes, nesting, ordering, #occurences
XSD와 DTD의 차이점
XSD also has data types, (typed) pointers, namespaces, keys and more.... unlike DTD
또한 XSD는 거의 장황하지만 구문은 XML의 확장이므로 빠르게 배우는 것이 편리합니다.
One difference is also that in a DTD, the content model of an element is completely determined by its name, independently of where it appears in the document. So, say you want to have a name
child element of your person
element that itself has child elements first
and last
. Then if you wanted to have a name
child element for a city
element in the same document, that would also need to have child elements first
and last
. In contrast, XML Schema allows you to declare child element types locally, so in this case you could declare the name
child elements for both person
and city
separately, giving them their proper content models in those contexts.
The other major difference is support for namespaces. Since DTDs are part of the original XML specification (and inherited from SGML), they are not namespace-aware at all because XML namespaces were specified later. You can use DTDs in combination with namespaces, but it requires some contortions, like being forced to define the prefixes in the DTD and using only those prefixes, instead of being able to use arbitrary prefixes.
To me, other differences are mostly superficial. Datatype support could easily be added to DTDs, and syntax is just syntax. (I, for one, find the XML Schema syntax horrible and would never want to hand-maintain an XML Schema, which I wouldn't say about DTDs or RELAX NG schemas; if I need an XML Schema for some reason, I usually write a RELAX NG one and convert it with trang
.)
Similarities:
DTDs and Schemas both perform the same basic functions:
- First, they both declare a laundry list of elements and attributes.
- Second, both describe how those elements are grouped, nested or used within the XML. In other words, they declare the rules by which you are allowing someone to create an XML file within your workflow, and
- Third, both DTDs and schemas provide methods for restricting, or forcing, the type or format of an element. For example, within the DTD or Schema you can force a date field to be written as 01/05/06 or 1/5/2006.
Differences:
DTDs are better for text-intensive applications, while schemas have several advantages for data-intensive workflows.
Schemas are written in XML and thusly follow the same rules, while DTDs are written in a completely different language.
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 can have only two types of data, the CDATA and the PCDATA. But in a schema you can use all the primitive data type that you use in the programming language and you have the flexibility of defining your own custom data types.
The developer building a schema can create custom data types based on the core data types and by using different operators and modifiers.
XML DTD
The purpose of a DTD is to define the structure of an XML document. It defines the structure with a list of legal elements:
<!ATTLIST contact type CDATA #IMPLIED>
<!ELEMENT address1 ( #PCDATA)>
<!ELEMENT city ( #PCDATA)>
<!ELEMENT state ( #PCDATA)>
<!ELEMENT zip ( #PCDATA)>
XML Schema
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>
When XML first came out, we were told it would solve all our problems: XML will be user-friendly, infinitely extensible, avoid strong-typing, and not require any programming skills. I learnt about DTD's and wrote my own XML parser. 15+ years later, I see that most XML is not user-friendly, and not very extensible (depending on its usage). As soon as some clever clogs hooked up XML to a database I knew that data types were all but inevitable. And, you should see the XSLT (transformation file) I had to work on the other day. If that isn't programming, I don't know what is! Nowadays it's not unusual to see all kinds of problems relating to XML data or interfaces gone bad. I love XML but, it has strayed far from its original altruistic starting point.
짧은 대답? XSD를 사용하면 XML 구조를보다 정확하게 정의 할 수 있기 때문에 DTD는 XSD를 위해 사용되지 않습니다.
DTD는 스키마 언어로서의 유용성이 제한되고 네임 스페이스를 지원하지 않으며 데이터 유형을 지원하지 않기 때문에 거의 사용되지 않습니다. 또한 DTD의 구문은 매우 복잡하여 이해하고 유지하기가 어렵습니다.
DTD는 XML 요소의 구문을 나타냅니다.
XML 스키마는 XML 유효성 검사를위한 Microsoft의 DTD 대안입니다.
참고 URL : https://stackoverflow.com/questions/1544200/what-is-difference-between-xml-schema-and-dtd
'development' 카테고리의 다른 글
중단 : 사용자 이름이 제공되지 않습니다 ( "hg help 구성"참조) (0) | 2020.06.01 |
---|---|
하위 프로세스 명령의 라이브 출력 (0) | 2020.06.01 |
“TypeError : 문자열 인덱스는 정수 여야합니다”가 표시되는 이유는 무엇입니까? (0) | 2020.06.01 |
JWT를 도난 당하면 어떻게됩니까? (0) | 2020.06.01 |
두 개의 ActiveRecord :: Relation 객체를 결합 (0) | 2020.06.01 |