Attribute Definition Lists - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Attribute Definition Lists

Description:

TITLE Grapes of Wrath /TITLE /BOOK OR BOOK ISBN='A2345' TITLE Grapes of Wrath /TITLE /BOOK Where are they declared? Attributes declared in the DTD ... – PowerPoint PPT presentation

Number of Views:678
Avg rating:3.0/5.0
Slides: 14
Provided by: madh
Category:

less

Transcript and Presenter's Notes

Title: Attribute Definition Lists


1
Attribute Definition Lists
  • Another part of the DTD

2
What are attributes?
  • Element content can be represented as attribute
    value
  • Example
  • ltBOOKgt
  • ltISBNgtA2345lt/ISBNgt
  • ltTITLEgtGrapes of Wrathlt/TITLEgt
  • lt/BOOKgt
  • OR
  • ltBOOK ISBNA2345gt
  • ltTITLEgtGrapes of Wrathlt/TITLEgt
  • lt/BOOKgt

3
Where are they declared?
  • Attributes declared in the DTD
  • If XML document has attributes, they must be in
    DTD for document to be valid
  • lt!DOCTYPE root element
  • lt!ELEMENT element-name(.)gt
  • lt!ATTLIST element-name Attribute-Name
    Attribute-type default-declarationgt
  • gt

4
Attribute Types
  • These are reserved words
  • Define the nature of the attribute value
  • Fall into three categories
  • String
  • Attribute value can be any text string
  • Enumerated
  • Attribute value must be selected from a list of
    possible values
  • Tokenized
  • Attribute value must be a valid XML name

5
String type attributes
  • Simplest form of attribute value
  • Form of declaration
  • Attribute-name CDATA
  • Example
  • lt!ATTLIST CUSTOMER CustID CDATA.gt

6
Enumerated type attributes
  • Attribute values are restricted to a set of
    values (enumerated types)
  • Example, a customer can only be of the type
    individual or corporate
  • attribute-name (value1value2value3)
  • CUSTOMER CustType (homebusiness)

7
Tokenized attribute types
  • DTDs support following tokens
  • ID (to create a unique identifier)
  • IDREF (allow attribute to reference ID of another
    element)
  • NMTOKEN (name token value restricted to valid XML
    name)
  • NMTOKENS (list of name tokens separated by
    blanks)

8
Tokens ID
  • lt!ATTLIST CUSTOMER CustID IDgt
  • ltCUSTOMER CustIDA123gtMadhult/CUSTOMERgt
  • ltCUSTOMER CustIDB721gtMikelt/CUSTOMERgt
  • The DTD would not be valid if both CustIDs were
    the same

9
Token IDREF
  • Refers to the ID attribute of another element
  • Lets say that a CUSTOMER makes an ORDER
  • lt!ATTLIST ORDER Orderby IDREFgt
  • ltORDER OrderbyA123gtSquash23456lt/ORDERgt

10
Token IDREFS
  • What happens if CUSTOMER has more than one order?
  • lt! ATTLIST CUSTOMER Orders IDREFSgt
  • ltCUSTOMER OrdersA123 B345 X390gtMadhult/CUSTOMERgt
  • All the orders must be found in the ID attribute
    of ORDER

11
Token NMTOKEN
  • Similar to String
  • Ensures that value of an attribute is a valid XML
    name
  • Main difference is that the string cannot contain
    blank spaces
  • Can be used if you wanted the attribute value to
    be a single word

12
Default Declaration
  • REQUIRED
  • Attribute must appear with each occurrence of the
    element
  • IMPLIED
  • Attribute is optional for the element
  • Default value
  • Attribute is optional
  • If no attribute value specified, it takes the
    default value
  • FIXED Default value
  • Attribute is optional
  • If attribute value is specified, it must be
    default value

13
What do these mean?
  • lt!ATTLIST CUSTOMER CustId ID REQUIREDgt
  • lt!ATTLIST CUSTOMER CustAdd (SeattleRedmondBellev
    ue) IMPLIEDgt
  • lt!ATTLIST ITEM ItemQty CDATA 1gt
  • Note that FIXED cannot be used for attributes of
    the type ID (why?)
Write a Comment
User Comments (0)
About PowerShow.com