Upload
tarik-hanson
View
16
Download
0
Embed Size (px)
DESCRIPTION
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. - PowerPoint PPT Presentation
Citation preview
3. Document Type Definitions(DTDs)
Data Warehousing Lab.
윤 혜 정
2Data Warehousing
Lab.DW
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
3Data Warehousing
Lab.DW
A Simple DTD ExampleDTD Examples :
<! ELEMENT person(name, profession*)>
<! ELEMENT name (first_name, last name)>
<! ELEMENT first_name (#PCDATA)>
<! ELEMENT last_name (#PCDATA)>
<! ELEMENT profession (#PCDATA)>
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>
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 : 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>
4Data Warehousing
Lab.DW
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 Tech
nology Group’s
XML well-formedness checker and validator : Richard Tobin
5Data Warehousing
Lab.DW
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
6Data Warehousing
Lab.DW
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>
7Data Warehousing
Lab.DW
Attribute Declarations
Attribute Type
Value Explanation
CDATA The value is character data
NMTOKEN The value is valid XML name
NMTOKENS
The value is a list of valid XML name
Enumeration
The value is a list of possible values for attribute
ENTITY The value is an entity
ENTITIES The value is a list of entities
ID The value is a unique id
IDREF The value is the id of another element
IDREFS The value is a list of other ids
NOTATION The value is name of notation
8Data Warehousing
Lab.DW
Attribute Declarations
Default value
Type Explanation
Default values The default value of the attribute
#REQUIRED The attribute value must be include in the element
#IMPLIED The attribute does not have to be include
#FIXED The attribute is fixed
9Data Warehousing
Lab.DW
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”.
10Data Warehousing
Lab.DW
Entities
Internal vs. External Parsed vs. Unparsed General vs. Parameter
Type Declared in Used in Always Parsed?
Internal General Internal DTD XML Doc Yes
External General External DTD XML Doc No
Internal Parameter
Internal DTD Internal DTD
Yes
External Parameter
External DTD External DTD
Yes
11Data Warehousing
Lab.DW
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“>
12Data Warehousing
Lab.DW
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>
13Data Warehousing
Lab.DW
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”>
14Data Warehousing
Lab.DW
Parameter Entities
Used within the DTD and must “parsed Entity” Using parameter Entities
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”>
15Data Warehousing
Lab.DW
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)>
16Data Warehousing
Lab.DW
Conditional Inclusion
XML offers the IGNORE directive for the purpose of “commenting out” a section of declaration.
<![ 긴급
[
<!ENTITY 추신 “매우 긴급하오니 반드시 3일내에 답장해 주십시요”
]]>
<![ 보통
[
<!ENTITY 추신 “그럼 답장을 기다리겠습니다 .”>
]]>
<!DOCTYPE 팩스 SYSTEM “ 팩스 .dtd”[
<!ENTITY % 긴급 “ IGNORE”>
<!ENTITY % 보통 “ INCLUDE”>
]>
< 팩스… .>
< 본문 >….
& 추신
</ 본문 >
</ 팩스 >