160 likes | 253 Views
3. Document Type Definitions(DTDs). Data Warehousing Lab. 윤 혜 정. Validation. The document must match a declaration in the DTD . The document satisfies the DTD then the document is said to be valid. The DTD lists all the Elements Attributes Entities. A Simple DTD Example.
E N D
3. Document Type Definitions(DTDs) Data Warehousing Lab. 윤 혜 정
Validation • The document must match a declaration in the DTD. • The document satisfies the DTD then the document is said to be valid. • The DTD lists all the • Elements • Attributes • Entities
A Simple DTD Example DTD Examples : <! ELEMENT person (name, profession*)> <! ELEMENT name (first_name, last name)> <! ELEMENT first_name (#PCDATA)> <! ELEMENT last_name (#PCDATA)> <! ELEMENT profession (#PCDATA)> XML Examples : NOT Valid : add a publication element <person> <name> <first_name>Alan</first_name> <last_name>Turing</last_name> </name> <profession> computer scientist</profession> <profession> cryptographer</profession> <publication>On computable Numbers….</publication> </person> XML Examples : NOT Valid : add some text outside the allowed children <person> <name> <first_name>Alan</first_name> <last_name>Turing</last_name> </name> was a <profession> computer scientist</profession> a <profession> cryptographer</profession> , and a </person> XML Examples : NOT Valid : profession elements comes before name <person> <profession> computer scientist</profession> <name> <first_name>Alan</first_name> <last_name>Turing</last_name> </name> </person> XML Examples : Valid <person> <name> <first_name>Alan</first_name> <last_name>Turing</last_name> </name> </person> XML Examples : NOT Valid : omits the name <person> <profession> computer scientist</profession> <profession> mathematician</profession> <profession> cryptographer</profession> </person>
The Document Type Declaration • The Document Type Declaration <!DOCTYPE person SYSTEM http://www.cafeconleche.org/dtds/person.dtd> • Internal DTD subsets & External DTD subsets • between the brackets is called the internal DTD • come from outside this documents are called external DTD • Validating a Document • XML validation Form : The Brown University Scholarly Technology Group’s • XML well-formedness checker and validator : Richard Tobin
Element Declarations • In a DTD, XML elements are declared with a DTD element declaration. • Basic form <!ELEMENT element_name content_specification> • Content_specification • Empty elements : EMPTY • Elements with only character data : #PCDATA • Elements with any contents : ANY • Elements with children (sequences) • The Number of Children • Choice • Mixed Content
Attribute Declarations • A valid document must declare all the element’s attributes. • ATTLIST declarations • A single ATTLIST can declare multiple attributes for a single element type. <!ATTLIST element-name attribute-name attribute-type default-value> Example : <!ATTLIST image source CDATA #REQURED> width CDATA #REQURED>
Attribute Declarations • Attribute Type
Attribute Declarations • Default value
Entities • Entities are storage containers used to hold data. • Entities are variables used to define shortcuts to common text. • The predefines five entities <(<) , &(&), >(>), "(“), '(‘) • Entities can be declared “internal or external”, “parsed or unparsed”, “general or parameter”.
Entities • Internal vs. External • Parsed vs. Unparsed • General vs. Parameter
External Parsed General Entities • Enable you to store some of your XML document in a separate file, making it reusable across multiple XML documents. • Gives you a chunk of reusable code. • Declared in the DTD using an ENTITY declaration. • SYSTEM or PUBLIC SYSTEM : document containing the contents of the entity is unregistered PUBLIC : document is registered. • Using External Parsed General Entities an ampersand(&) and followed by a semicolon(;); &footer <!ENTITY Entity_Name SYSTEM “location”> <!ENTITY Entity_Name PUBIC “location_1” “location_2”> Example : <!ENTITY footer SYSTEM “http://www.oreilly.com/boilerplate/footer.xml“>
External Unparsed General Entities • XML parser will not try to parse the entity’s contents. • Data within the entity is ignored by the XML parser and passed to the application that is using the document. • Notations used by the application to identify the type of data in entity. <!NOTATION jpeg SYSTEM “image/jpeg”> • Declaring an External Unparsed General Entity <!ENTITY turing_getting_off_bus SYSTEM http://www.turing.org.uk/turing/pi1/bus.jpg NDATA jpeg>
External Unparsed General Entities • Embedding Unparsed Entities in Documents <!ELEMENT image EMPTY> <!ATTLIST image source ENTITY #REQUIED> • Using External Unparsed Entities <image source =“&turing_getting_off_bus”>
Parameter Entities • Used within the DTD and must “parsed Entity” • Using parameterEntities an percent(%) and followed by a semicolon(;) • Example <!ELEMENT apartment (address, footage, rooms, baths, rent)> <!ELEMENT sublet (address, footage, rooms, baths, rent)> <!ELEMENT coop (address, footage, rooms, baths, price)> <!ELEMENT house (address, footage, rooms, baths, price)> <!ENTITY % residential_content “address, footage, rooms, baths”> <!ENTITY % rental_content “rent”> <!ENTITY % purchase_content “price”>
Parameter Entities <!ELEMENT apartment (%residential_content;, %rental_content;)> <!ELEMENT sublet (%residential_content;, %rental_content;)> <!ELEMENT coop (%residential_content;, %purchase_content;)> <!ELEMENT house (%residential_content;, %purchase_content;)> <!ELEMENT apartment (address, footage, rooms, baths, rent)> <!ELEMENT sublet (address, footage, rooms, baths, rent)> <!ELEMENT coop (address, footage, rooms, baths, price)> <!ELEMENT house (address, footage, rooms, baths, price)>
Conditional Inclusion • XML offers the IGNORE directive for the purpose of “commenting out” a section of declaration. <![긴급 [ <!ENTITY 추신 “매우 긴급하오니 반드시 3일내에 답장해 주십시요” ]]> <!DOCTYPE 팩스 SYSTEM “팩스.dtd”[ <!ENTITY % 긴급 “IGNORE”> <!ENTITY % 보통 “INCLUDE”> ]> <팩스….> <본문>…. &추신 </본문> </팩스> <![보통 [ <!ENTITY 추신 “그럼 답장을 기다리겠습니다.”> ]]>