640 likes | 741 Views
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
E N D
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
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
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.
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
Declare A Container Element • Elements that belong to namespaces must be referenced in DTDs by their fully qualified names. • Example,
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.
Declare A Optional Element • Optional elements • Elements contained zero or more values at runtime <!ELEMENT containerElement ( [ optionalElementN* ] ) >
Declare A Multiple Occurring Element • Multiple Occurring elements • Elements contained at least one or more values at runtime
Declare Multiple Elements • Multiple elements must be separated by commons, like this (aRequiredElement+, anotherRequiredElement, anOptionalElement*)
Declare An Character Data Element • Use #PCDATA keyword • #PCDATA is case-sensitive • Cannot contain other predefined elements
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”
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
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
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