XML(8) Document Type Definitions(DTD)

来源:互联网 发布:阿芙精油 知乎 编辑:程序博客网 时间:2024/05/01 04:37

external DTD example name.dtd:

<!ELEMENT name (first, middle, last)><!ELEMENT first (#PCDATA)><!ELEMENT middle (#PCDATA)><!ELEMENT last (#PCDATA)>

name.xml

<?xml version="1.0"?><!DOCTYPE name SYSTEM "C:\Users\Xing Hua Zhang\Desktop\name.dtd"><name><first>John</first><middle>Fitzgerald Johansen</middle><last>Doe</last></name>

internal DTD

When declarations appear between the [ and ], as in the sample, they are called internal subset declarations.

 example:

<?xml version="1.0"?><!DOCTYPE name [    <!ELEMENT name (first, middle, last)>    <!ELEMENT first (#PCDATA)>    <!ELEMENT middle (#PCDATA)>    <!ELEMENT last (#PCDATA)>]><name>   <first>John</first>   <middle>Fitzgerald Johansen</middle>   <last>Doe</last></name>



Document Type Declaration

<!DOCTYPE name [ ]>


System Identifiers

A system identifier allows you to specify the location of an external file containing DTD declarations. It is comprised of SYSTEM identifiers and URI reference

format:

<!DOCTYPE name SYSTEM "name.dtd" [...]>

<!DOCTYPE name SYSTEM "file:///c:/name.dtd" [ ]>
<!DOCTYPE name SYSTEM "http://website.com/hr/name.dtd" [ ]>
<!DOCTYPE name SYSTEM "name.dtd">


Public identifiers

FPI Format:

<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location">

public identifiers can follow any format, Formal Public Identifiers is the most commonly used format


An example of public identifier:

<!DOCTYPE name PUBLIC "-//Beginning XML//DTD Name Example//EN" "name.dtd">

notice name.dtd is usually a relative path, this is decided by the parser.









原创粉丝点击