
Document Type Definition (文書型定義、 DTD )とは、 マークアップ言語 SGMLおよびXMLにおいて、文書構造(文書型)を定義するためのスキーマ言語の一つである。 Document Type Definition (Document Type Definition, DTD) is a markup language SGML and XML in the structure document (document type) is one of the language schema to define.
DTDでは、SGMLやXMLの文書内に記述することができる要素やその発生順序、発生回数、要素がもつ属性、属性の型などを記述することができる。 In DTD, SGML or XML elements and their order can be raised in the written documents, occurrences, elements with attributes, and can describe the types of attributes.
他のスキーマ言語と同様に、DTDにおいても、文書構造を厳密に定義することによって、SGMLやXMLの技術を利用する際の、処理の正確性や安全性を高めることができる。 As with other schema language, DTD even by strictly defining the document structure, SGML or XML when using the technology can enhance the safety and accuracy of processing. SGMLやXMLの文書処理を支援するライブラリの多くは、SGMLやXMLの文書がDTDによる文書構造に従っているかどうかを検証する機能を備えている。 Many of SGML and XML libraries to assist in the processing of documents, SGML DTD and XML documents have the ability to verify whether the documents comply with the structure.
もともとはSGMLのスキーマ言語として開発され、SGMLから派生したXMLにおいても、スキーマ言語として採用されている。 Was originally developed as a schema language of SGML, SGML-derived in XML has been adopted as a schema language. 例えば、SGMLの応用技術であるHTMLや、XMLの応用技術であるXHTMLでは、DTDによって文書構造が定義されている。 For example, SGML is a technical application of HTML and, XML technology is the application of XHTML in, DTD has been defined by the document structure.
現在では、XML技術を利用する場合には、スキーマ言語としてDTDを採用するケースは少なくなる傾向にある。 Today, XML is when to use technology as a case adopting the DTD schema language tends to be less. XMLが勧告された後、DTDに対してはいくつかの欠点(XMLの文法とは異なる文法を採用している、 XML名前空間に対応していない など)が問題として指摘されてきたためである。 After being recommended by XML, DTD is a drawback for some (XML syntax and grammar that uses a different, and not XML namespace support) because the problem has been pointed out. そのため、XML技術は広く普及したものの、DTDの欠点が XML技術を柔軟に活用する際の障害の一つとなっていた。 Thus, XML technologies, but widespread, DTD had the disadvantage of XML is one of the failure to take advantage of the flexibility of technology.
この問題を解決するために、新たなスキーマ言語としてRELAX NGやW3C XML Schemaなどが開発され、それらを採用する事例が増えている。 To solve this problem, a new schema language RELAX NG and W3C XML Schema has been developed, including a growing number of cases to adopt them.
目次 Contents |
DTDは、 要素型宣言 、 属性リスト宣言 、 エンティティ宣言 (または、 実体参照宣言 )、 記法宣言により構成される。 DTD, the element type declaration, attribute list declarations, entity declarations (or DTD), consists of a notation declaration.
対象のSGML / XML文書において使用する要素を宣言し、その要素の名前、関連する要素との親子関係および出現順序を定義する。 Target SGML / XML to declare the elements used in the document, the name of the element that defines the order and appearance-related factors and parent-child relationship.
<!ELEMENT 要素名構成要素 > <! ELEMENT element name component "
このとき、要素名は、対象の要素の名前であり、構成要素は、以下の種類に分けられる。 In this case, the element name is the name of the elements of the target component is divided into the following types.
対象要素に子要素が存在しない場合(例えば、後述する属性のみの場合など)に指定する。 If there is no child element to the target element (for example, if the only attributes that later) you specify.
<!ELEMENT foo1 EMPTY> <! ELEMENT foo1 EMPTY>
対象要素配下に任意の要素、任意のデータが格納される場合に指定する。 Under any element of the target element, to specify if any data is stored.
<!ELEMENT foo2 ANY> <! ELEMENT foo2 ANY>
対象要素配下の子要素の順番および出現回数を指定する。 Specify the number of occurrences of child elements under the order and the target element.
<!ELEMENT foo1 (bar1,(bar2|bar3)*)> <! ELEMENT foo1 (bar1, (bar2 | bar3) *)>
対象のSGML/XML文書の要素が持つ属性の型やデフォルト値を定義する Target SGML / XML to define default values of attributes and elements of the document type
<!ATTLIST 要素名属性名属性値の候補、または型デフォルト値 > <! ATTLIST element name attribute name attribute value candidates, the default value or type "
例えば、俳優の出身地域を属性として定義する場合、以下のような属性リストが考えられる。 For example, if you define the area as an attribute of the actor who is considered the following attribute list.
<!ATTLIST 俳優 出身地域 (北海道|東北|関東|甲信越|東海|北陸|近畿|四国|九州|沖縄) "関東"> <! ATTLIST actor-turned-district (Hokkaido | Tohoku | Kanto | Koshinetsu | Tokai | Hokuriku | Kinki | Shikoku | Kyushu | Okinawa) "Kanto" " ... ... <俳優 出身地域="東海">俳優A</俳優> "Actor-turned-region =" East Sea "" Actor A </ actor "
エンティティ宣言は、対象のSGML/XML文書内に記述できるエンティティ参照について定義する。 Entity declarations, for which SGML / XML to define the entity reference can be described in the document. SGML/XML文書内でエンティティ参照を記述すると、DTDのエンティティ宣言にしたがって、文字列を置換したり、外部ファイルの内容を埋め込むことができる。 SGML / XML to describe the entity reference in the document, DTD entities according to the declaration, or replace a string can be embedded in the content of external files.
<!ENTITY greeting "こんにちは"> <! ENTITY greeting "Hello" " <!ENTITY external-file SYSTEM "external.xml"> <! ENTITY external-file SYSTEM "external.xml">
記法宣言は、対象のSGML/XML文書内から参照する外部ファイルの種類 (例えばJPEGなど) を指定する。 Notation declaration is being SGML / XML file types from an external reference in a document (eg, JPEG, etc.) is specified.
簡単なDTDの例を示す。 An example of a simple DTD.
<!ELEMENT firstName (#PCDATA)> <! ELEMENT firstName (# PCDATA)> <!ELEMENT secondName (#PCDATA)> <! ELEMENT secondName (# PCDATA)> <!ELEMENT info ANY> <! ELEMENT info ANY> <!ELEMENT data (firstName,secondName,info?)> <! ELEMENT data (firstName, secondName, info?)> <!ELEMENT myDocument (data)*> <! ELEMENT myDocument (data) *> <!ATTLIST data age CDATA #IMPLIED> <! ATTLIST data age CDATA # IMPLIED>
このDTDでは以下の内容が記述されている。 This DTD is described in what follows.
firstName要素を宣言している。 First line: firstName element has been declared. この要素は内容として文字列データをもつ。 This element, as a string with the data. secondName要素を宣言している。 Second row: secondName elements are declared. 内容として文字列データをもつ。 String data with the content. info要素を宣言している。 Third row: info element has been declared. 内容として、このDTDで宣言された任意の要素や文字列データを、もつことができる。 The contents of this DTD or string data that is declared in any element, can have. data要素を宣言している。 Fourth row: data elements are declared. 内容としてfirstName 、 secondName 、 infoの各要素をもつ。 The contents firstName secondName info with each element. 要素の出現順序はこの順番でなければならない(例えばfirstNameの前にsecondNameが出現してはならない)。 Must be a sequence of elements in this order (eg firstName before secondName should then appear). ?はオプショナルであることを示す。 ? Is shown that it is optional. info要素はsecondName要素の後に、出現しても良いし出現しなくても良い。 info element secondName after the elements, without having a good appearance and the emergence of good. myDocument要素を宣言している。 Fifth row: myDocument elements are declared. 内容として0個からn個のdata要素をもつ。 N 0 from a single individual, as a data element with. data要素の属性リスト宣言をしている。 6th row: data element and attribute list declaration. data要素は age属性をもつ。 data要素は with the attribute age. age属性は文字列データであり、省略することが可能である。 age attribute is a string data, which can be omitted. このDTDに従って作成したXML文書の例 According to this DTD to create XML document example
<?xml version = "1.0" encoding = "UTF-8" ?> <? xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE myDocument SYSTEM "example.dtd"> <! DOCTYPE myDocument SYSTEM "example.dtd"> <myDocument > <myDocument> <data age = "29" > <data age = "29"> <firstName > Fred </firstName > <firstName> Fred </ firstName> <secondName > Bloggs </secondName > <secondName> Bloggs </ secondName> </data > </ data> <data > <data> <firstName > Tony </firstName > <firstName> Tony </ firstName> <secondName > Blair </secondName > <secondName> Blair </ secondName> <info > PM of UK </info > <info> PM of UK </ info> </data > </ data> </myDocument > </ myDocument>
