Top Banner
Declare A DTD File
64

Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A DTD File

Page 2: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A DTD Inline File

• For example, use DTD to restrict the value of an XML

document to contain only character data.

Page 3: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Inline DTD

• Include the text for a DTD inside the XML document

• For short XML documents

• For all XML documents during the development process and if you do not intend your DTD to be applied to other XML documents

Page 4: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Inline DTD

Page 5: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 6: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

• Restrict “GREETING” to contain characters only

Page 7: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Types of XML Element

Page 8: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

External DTD

• Save the text for a DTD as a separate file and refer this file inside your XML document

• Using “DOCTYPE” declaration with the “SYSTEM” keyword

• Add path name if the DTD file is in different path from the XML file

Page 9: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

External DTD

Page 10: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 11: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 12: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Comment DTD Files

Page 13: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Comment DTD Files

Page 14: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Comment DTD Files

Page 15: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Comment DTD Files

Page 16: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Container Element

• Elements that consist of other, predefined elements

• Can enforce container relationships on XML data at run time

• The ability to enforce container relationships enables you to model complex relationships between XML data– model relationships between employees,

projects, orders, products, retailers, etc.

Page 17: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Container Element

Page 18: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 19: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Container Element

• Contained elements need not to be declared in the same order in the DTD as they are in the XML document

• Indenting each contained element makes identifying the relationships between elements much easier

Page 20: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Container Element

• Elements that belong to namespaces must be referenced in DTDs by their fully qualified names.

• Example,

Page 21: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 22: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Required Element

• Required element– Created by validation rule to ensure that a given

element is associated with one – and only one – value at runtime

– Typically defined as contained elements– E.g.,

• Customer name• Social Security number• Product Identification number• Account number• Etc.

Page 23: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Required Element

Page 24: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Required Element

Page 25: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Required Element

Page 26: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Optional Element

• Optional elements– Elements contained zero or more values at runtime

<!ELEMENT containerElement ( [ optionalElementN* ] ) >

Page 27: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Multiple Occurring Element

• Multiple Occurring elements– Elements contained at least one or more

values at runtime

Page 28: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Multiple Occurring Element

Page 29: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare A Multiple Occurring Element

Page 30: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Multiple Elements

• Multiple elements must be separated by commons, like this

(aRequiredElement+, anotherRequiredElement, anOptionalElement*)

Page 31: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare An Character Data Element

• Use #PCDATA keyword• #PCDATA is case-sensitive• Cannot contain other predefined elements

Page 32: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 33: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare An Character Data Element

Page 34: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare An Empty Element

• Empty elements– Elements contained no data at runtime– Use to aggregate data , rather than to define specific

values• E.g., consider the element named “productDescription”

Page 35: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 36: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare An Empty Element

Page 37: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes That Hold Characters

Page 38: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.
Page 39: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes That Hold Characters

Page 40: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define An Entity

• Define a validation rule to constrain the value of an XML attribute to a developer-defined external data source

• Enables you to organize XML code in multiple files and pull the XML code together at runtime

• Use ENTITY keyword to declare an attribute of external type

• At runtime, the only data types allowed for an element declared as type ENTITY are those data types defined in the DTD file using <!ENTITY> declaration

Page 41: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define An Entity

Page 42: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define An Entity

Page 43: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define An Entity

Page 44: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes As Words

• Define a validation rule using the NMTOKEN keyword to constrain the value of an XML attribute to a single word, or token

• To constrain a value to a collection of individual tokens, can use the NMTOKENS keyword

Page 45: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes As Words

Page 46: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes As Words

Page 47: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes As Words

Page 48: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes As Words

Page 49: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Attributes As Words

Page 50: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Restrict Attributes to Lists of Options

• Constrain XML attribute value to one in a list of predefined options

• Can declare an attribute of type enumerates list• Helps reduce input errors

Page 51: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Restrict Attributes to Lists of Options

Page 52: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Unique-Identifier Attributes

• Constrain an attribute to accept unique values

Page 53: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Unique-Identifier Attributes

Page 54: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Unique-Identifier Attributes

Page 55: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Declare Unique-Identifier Attributes

Page 56: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Reference Existing Identifiers

• Use IDREF to ensure that the value of an XML attribute matches the value of previously defined attribute

Page 57: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Reference Existing Identifiers

Page 58: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Reference Existing Identifiers

Page 59: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Reference Existing Identifiers

Page 60: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define and Reuse Text Within DTDs

• Describe a single of text, called parameter entity• Reference the chunk repeatedly inside a DTD

file• Helps reduce errors introduced by retyping• Define entities before using them• Use <!ENTITY> and a sign % with a space on

both sides.– The % sign denotes that this entity is a parameter

entity

Page 61: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define and Reuse Text Within DTDs

• An internal parameter entity

<!ENTITY % name “what is being replaced”>

• An external parameter entity– Use URL what the content is located

<!ENTITY % name URL >

Page 62: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define and Reuse Text Within DTDs

Page 63: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define and Reuse Text Within DTDs

Page 64: Declare A DTD File. Declare A DTD Inline File For example, use DTD to restrict the value of an XML document to contain only character data.

Define and Reuse Text Within DTDs