Presentation is loading. Please wait.

Presentation is loading. Please wait.

CH 9 Attribute Declaration 1. Objective What is an attribute Declaring attributes Declaring multiple attribute Alternatives to default attributes values.

Similar presentations


Presentation on theme: "CH 9 Attribute Declaration 1. Objective What is an attribute Declaring attributes Declaring multiple attribute Alternatives to default attributes values."— Presentation transcript:

1 CH 9 Attribute Declaration 1

2 Objective What is an attribute Declaring attributes Declaring multiple attribute Alternatives to default attributes values Attribute types A DTD for attribute based Television listings 2

3 What Is an Attribute? Attribute is nothing but pairs name-values pairs separated by an equals sign(=) Example In the above example, GREETING element has language attribute, which has value English Hello XML! 3

4 Declaring Attributes Like elements, attributes must be Declared in DTD for the document to be valid Attributes are declared by an attribute list in the following form 4

5 Declaring Attributes cont... <! starts all declarations ATTLIST is the keyword that indicates this is an attribute list Element_name is the name of the element possessing this attribute Attribute_name is the name of the attribute. Type is the kind of attribute Default_value is the value the attribute takes on if no value is specified for the attribute 5

6 Declaring Attributes cont… Attribute Types TypeMeaning CDATACharacter data—text that is not markup EnumeratedA list of possible values from which exactly one will be chosen IDA unique name not shared by any other ID type attribute in the document IDREFThe value of an ID type attribute of an element in the document IDREFSMultiple IDs of elements separated by white space ENTITYThe name of an unparsed entity declared in the DTD ENTITIESMultiple names of unparsed entities declared in the DTD, separated by white space NMTOKENAn XML name token NMTOKENSMultiple XML name tokens separated by white space NOTATIONOne or more names of notations declared in the DTD 6

7 Declaring Attributes cont… For example, consider the following declaration says that GREETING elements have an attribute with the name LANGUAGE and the type CDATA The word English in quotation marks is the default value Salut! Salut! 7

8 Declaring Attributes cont… The attribute is declared separately from the element itself If other elements also have LANGUAGE attributes, they require separate declarations 8

9 Declaring Multiple Attributes Elements often have more than one attribute The preceding example says that RECTANGLE elements possess LENGTH and WIDTH attributes Each of which has the default value “0px” 9

10 Declaring Multiple Attributes You can combine two declarations into a single declaration Attributes are unordered. Both of the following elements are valid 10

11 Alternatives to Default Attribute Values Instead of specifying an explicit default attribute value such as 0px An attribute declaration can require the author to provide a value Allow the value to be omitted completely Even always use the default value These requirements are specified with the three keywords #REQUIRED #IMPLIED #FIXED 11

12 #REQUIRED #REQUIRED is used to force values to be provide for attributes #REQUIRED helps you guarantee that the minimum information necessary for processing a document is present <AUTHOR NAME=”Elliotte Rusty Harold” EMAIL=”elharo@metalab.unc.edu” EXTENSION=”4093”/> <AUTHOR NAME=”Elliotte Rusty Harold” EMAIL=”elharo@metalab.unc.edu” EXTENSION=”4093”/> 12

13 #IMPLIED option default value Sometimes you may not have a good option for a default value, but you do not want To require the author of the document to include the attribute either <AUTHOR NAME=”Elliotte Rusty Harold” EMAIL=”elharo@metalab.unc.edu” /> <AUTHOR NAME=”Elliotte Rusty Harold” EMAIL=”elharo@metalab.unc.edu” /> 13

14 #IMPLIED cont… Attribute values are almost never set to N/A unknown, or the empty string An illegal flag value such as -1 If the value of an attribute is not known or not available, simply omit it from the instance document, and declare it #IMPLIED in the DTD 14

15 #FIXED Provide a default value for the attribute without allowing the author to change it <AUTHOR NAME=”Elliotte Rusty Harold” COMPANY=”TIC” EMAIL=”elharo@metalab.unc.edu” EXTENSION=”3459”/> <AUTHOR NAME=”Elliotte Rusty Harold” COMPANY=”TIC” EMAIL=”elharo@metalab.unc.edu” EXTENSION=”3459”/> 15

16 Attribute Types - CDATA CDATA - means the attribute value may be any string of text not containing a less than sign (<) or quotation marks (“) 16

17 Attribute Types - NMTOKEN NMTOKEN - restricts the value of the attribute to a legal XML name token 17

18 Attribute Types - NMTOKENS NMTOKENS NMTOKENS - attribute type is the plural form of NMTOKEN Enables the value of the attribute to consist of multiple XML name tokens that are separated from each other by white space 18

19 Attribute Types - enumerated Enumerated is not an XML keyword, but a list of possible values for the attribute. It is separated with vertical bars Suppose you want an element to be visible or invisible. You may want the element to have a VISIBLE attribute It can only have the values TRUE or FALSE 19

20 Attribute Types –ID ID type attribute uniquely identifies an element in the document An attribute value of type ID must be a valid XML name The ID type is incompatible with #FIXED 20

21 Attribute Types –ID cont… <!DOCTYPE DOCUMENT [ ]> The quick brown fox <!DOCTYPE DOCUMENT [ ]> The quick brown fox 21

22 Attribute Type - ENTITY An ENTITY type attribute enables you to link external binary data 22

23 references http://www.w3schools.com/dtd/dtd_building.asp http://www.w3schools.com/xsl/xsl_intro.asp 23


Download ppt "CH 9 Attribute Declaration 1. Objective What is an attribute Declaring attributes Declaring multiple attribute Alternatives to default attributes values."

Similar presentations


Ads by Google