Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 34 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
34
Dung lượng
408,5 KB
Nội dung
1 2 A DTD adds syntactical requirements in addition to the well-formed requirement It helps in eliminating errors when creating or editing XML documents It clarifies the intended semantics It simplifies the processing of XML documents 3 !" In an address book, where can a phone number appear? # $%&'(%&' %)* If we have to check for all possibilities, processing takes longer and it may not be clear to whom a phone belongs 4 Document Type Definitions (DTDs) impose structure on XML documents There is some relationship between a DTD and a schema, but it is not close – hence the need for additional “typing” systems (XML schemas) The DTD is a syntactic specification 5 !"+ %%,- <person> <name> Homer Simpson </name> <greet> Dr. H. Simpson </greet> <addr>1234 Springwater Road </addr> <addr> Springfield USA, 98765 </addr> <tel> (321) 786 2543 </tel> <fax> (321) 786 2544 </fax> <tel> (321) 786 2544 </tel> <email> homer@math.springfield.edu </email> </person> Mixed telephones and faxes As many as needed As many address lines as needed (in order) At most one greeting Exactly one name 6 . name to specify a name element greet? to specify an optional (0 or 1) greet elements name, greet? to specify a name followed by an optional greet 7 . /% addr* to specify 0 or more address lines tel | fax a tel or a fax element (tel | fax)* 0 or more repeats of tel or fax email* 0 or more email elements 8 . /% So the whole structure of a person entry is specified by (*(%%0(1."0(0 This is known as a regular expression 9 ! for each element type E, a declaration of the form: <!ELEMENT E P> where P is a regular expression, i.e., P ::= EMPTY | ANY | #PCDATA | E’ | P1, P2 | P1 | P2 | P? | P+ | P* # !/+ # 23(24+ # 23124+%5 # 2*+ # 26+ # 20+7 10 .8 !" A The tag (i.e., element) A occurs e1,e2 The expression e1 followed by e2 e* 0 or more occurrences of e e? Optional: 0 or 1 occurrences e+ 1 or more occurrences e1 | e2 either e1 or e2 (e) grouping [...]... The DTD is part of the document file • or external – The DTD and the document are on separate files – An external DTD may reside • In the local file system (where the document is) • In a remote file system 31 Connecting a Document with its DTD • An internal DTD: • A DTD from the local file system: • A DTD. .. 32 Well-Formed XML Documents • An XML document (with or without a DTD) is well-formed if – Tags are syntactically correct – Every tag has an end tag An XML document – Tags are properly nested must be well – There is a root tag formed – A start tag does not have two occurrences of the same attribute 33 Valid Documents • A well-formed XML document. .. 0 or more times 12 An Address-Book XML Document with an Internal DTD The name of The syntax of a DTD is not XML ... given document) must have different values for the ID attribute (no confusion) • Even if the two elements have different element names •If an attribute is declared as IDREF – The associated value must exist as the value of some ID attribute (no dangling “pointers”) •Similarly for all the values of an IDREFS attribute •ID, IDREF and IDREFS attributes are not typed 30 Adding a DTD to the Document • A DTD. .. Specifying Attributes in the DTD The dimension attribute is required The accuracy attribute is optional CDATA is the type of the attribute – it means “character data,” and may take any literal string as a value 19 The Format of an Attribute Definition • -type defaultvalue> •... that is a descendent of herself 22 Recursive DTDs (cont’d) father ]> If a person only has a father, how can you tell that he has a father and does not have a mother? What is now the problem with this? 23 Using ID and IDREF Attributes document – An element can have at most one ID attribute – No default (fixed default) value is allowed • #required: a value must be provided • #implied: a value is optional • IDREF attribute: its value must be some other element’s ID value in the document • IDREFS attribute: its value is a set, each element of the set is the ID value of some other element in the document DTD is not XML syntax ]> “Internal” means that the DTD and the 13 XML Document are in the same file The Rest of the Address-Book XML Document Jeff Cohen Dr Cohen jc@penny.com 14 Regular Expressions...The Definition of an Element Consists of Exactly One of the Following • A regular expression (as defined earlier) • EMPTY means that the element has no content • ANY means that content can be any mixture of PCDATA and elements defined in the DTD • Mixed content which is defined as described on the next slide • (#PCDATA) 11 The Definition of Mixed Content • Mixed content... value is given inside quotes • attribute types: – CDATA – ID, IDREF, IDREFS –… 20 Summary of Attribute Default Values • #REQUIRED means that the attribute must by included in the element • #IMPLIED • #FIXED “value” – The given value (inside quotes) is the only possible one • “value” – The default value of the attribute if none is given 21 Recursive DTDs . phone belongs 4 Document Type Definitions (DTDs) impose structure on XML documents There is some relationship between a DTD and a schema, but it is not close – hence. (#PCDATA)> <!ELEMENT email (#PCDATA)> ]> The name of the DTD is addressbook “Internal” means that the DTD and the XML Document are in the same file " . not " 14 8. . 1 2 A DTD adds syntactical requirements in addition to the well-formed requirement It helps in eliminating errors when creating or editing XML documents It clarifies