Document type definitions part 2


Published on

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Document type definitions part 2

  1. 1. Document Type Definitions – Elements & Attributes<br />XML<br />
  2. 2. How many times can an element occur?<br />How many times must an element occur?<br />Cardinality<br />
  3. 3. A student must have a first name<br />A student may or may not have a last name<br />A student may have one or more majors, or none (undeclared)<br /> <!ELEMENT student (first, last?, major*)><br />Note: Cardinality indicator doesn’t affect the element declaration (i.e. major)<br />Cardinality: Example<br />
  4. 4. Elements tend to be used to describe a logical unit of information<br />Attributes are typically used to store data about characteristics (properties)<br />May have a Movie element with attributes for Title, Rental Price, Rental Days<br />No specific rules about how to use elements and attributes<br />Attributes and DTD’s<br />
  5. 5. Attributes allow more limits on data<br />Can have a list of acceptable values<br />Can have a default value<br />Some ability to specify a data type<br />Concise, about a single name/value pair<br />Attributes have limits<br />Can’t store long strings of text<br />Can’t nest values<br />Whitespace can’t be ignored<br />Attributes and Elements<br />
  6. 6. Declaration:<br /><!ATTLISTElementNameAttrNameAttrType Default><br />Specify the Element the attribute belongs to<br />Specify the Name of the attribute<br />Specify the Type of data the attribute stores<br />Specify characteristics of the values (Default or attribute value)<br />List either the default value or other characteristic of value – required, optional<br />Specifying Attributes<br />
  7. 7. CDATA – unparsed character data<br />Enumerated – series/list of string values<br />Entity/Entities – reference entity definition(s)<br />ID – unique identifier for the element<br />IDREF – refer to the ID of another element<br />IDREFS – list of ID’s of other elements separated by whitespace<br />NMTOKEN/NMTOKENS – value(s) of attribute can be anything that follows rules for XML name<br />Sample Attribute Data Types<br />
  8. 8. Specifies that attribute value must be found in a particular list<br />Each value in list must be valid XML name<br />Limits on spaces, characters<br />Use | (pipe) to separate members of list<br />If specifying list letter grades for a student:<br /><!ATTLIST student grade (A | B | C | D | F | V | W | I) #IMPLIED><br />Enumerated Attributes<br />Element<br />Attribute<br />Enumerated List<br />
  9. 9. An ID specifies that the element must have a unique value within the document<br />Allows reliable way to refer to a specific element<br />No spaces allowed in value<br />Typically replace space with underscore<br />Attribute list can include only one ID<br />IDREF, IDREFS allows an element to be associated with another or multiple other elements<br />A student element must have a student ID:<br /><!ATTLIST student studentID ID #REQUIRED><br />ID, IDREF, IDREFS<br />
  10. 10. Attributes can refer to entities<br />“Entity” refers to substituting a reference for a text value<br />&amp; refers to the & character<br />Unparsed Entity is a reference that isn’t parsed<br />Can reuse references for long values, or hard to manage characters (i.e. tab, line feed)<br />Entity must be declared in the DTD<br /><!ENTITY classTitle “XML”><br />When classTitle found in document, replaced with XML<br />Entities and Attributes<br />
  11. 11. Can specify how the value will appear in the document<br />Must always specify a value declaration<br />DEFAULT sets a value for an attribute if a value isn’t provided<br />Include default value in double quotes<br />FIXED sets a value that must occur; if an attribute has a different value, a validation error occurs<br />REQUIRED specifies that the attribute (and value) must exist<br />IMPLIED means the attribute is optional<br />Attribute Value Declarations<br />