1 / 24

Data Type Definition

Data Type Definition. Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University. Elements Attributes. Entity Notations. Components of XML Systems. XSL Java. XML Document ( Contents ). Well-Formed (Syntax). XML Application. XML Parser

Download Presentation

Data Type Definition

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Type Definition Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Entity Notations

  2. Components of XML Systems XSL Java . . . XML Document (Contents) Well-Formed (Syntax) XML Application XML Parser (Processor) DTD Validate (Structure) ASP Perl . . . Schema Database Database (Rules)

  3. Issue Warning/Stop Processing XML Document Issue Warning/Stop Processing Further Processing Data Type Definition How a Parser Interprets XML - Validate (optional) yes no Well Formed? DTD? no yes yes no Valid?

  4. Comments ProcessingInstructions ElementDeclaration AttributeDeclaration EntityDeclaration NotationsDeclaration Attributes PCDATA EntityReferences The Panoramic Perspective of XML Prolog Comments XMLDocument Doc. TypeDeclaration Doc TypeDefinitions ProcessingInstructions Comments ProcessingInstructions CDATA,Entities, ID,.. RootElement Elements EntityReferences : Optional CDATASections

  5. Purposes of DTD • What elements should be presented? • How many of each element were required? • What kind of element content was permitted? • In what order the elements should appear? DTD is used to specify which elements are allowed where in the document. An DTD file provides the following information:

  6. Components of DTD • Comments • Element Type Declarations • Attribute List Declarations • Entity Declarations • Notations Declarations

  7. DTD Declaration • DTD is optional. Declaration is provided in the XML document. External: • <?xml version = "1.0" standalone = "no"?> • <!DOCTYPE Root Element SYSTEM “xxx.dtd"> Internal: • <?xml version = "1.0" standalone = “yes"?> • <!DOCTYPE Root Element [ • Contents of DTD • ]>

  8. Comments • A place to write a note for reminding, simple documentation, or commenting out codes for debugging, etc., which will not be seen by the end users. <!-- This is a comment area --> • You can use any character inside the comment area except “--” itself • There is no limitation on the length of the comment area.

  9. Tree Diagram of Address Document Address_ Book Root Element Contact* Name ID E-mail Phone Address Street City State Zip

  10. Example of DTD File Root Element • <!ELEMENT Address_Book (Contact)*> • <!ELEMENT Contact (Name,ID,EMAIL,Phone,Address)> • <!ELEMENT Name (#PCDATA) > • <!ELEMENT ID (#PCDATA) > • <!ELEMENT EMAIL (#PCDATA) > • <!ELEMENT Phone (#PCDATA) > • <!ELEMENT Address (Street,City,State, ZIP) > • <!ELEMENT Street (#PCDATA) > • <!ELEMENT City (#PCDATA) > • <!ELEMENT State (#PCDATA) > • <!ELEMENT ZIP (#PCDATA) >

  11. Name Description? Ingredients? optional isVegetarian Instructions? Tree Diagram for Recipe Recipe Qty unit Ingredient* Item Step+

  12. Example of DTD File <!ELEMENT Recipe (Name, Description?, Ingredients?, Instructions?)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Description (#PCDATA)> <!ELEMENT Ingredients (Ingredient)*> <!ELEMENT Ingredient (Qty, Item)> <!ELEMENT Qty (#PCDATA)> <!ATTLIST Qty unit CDATA #REQUIRED> <!ELEMENT Item (#PCDATA)> <!ATTLIST Item optional CDATA "0" isVegetarian CDATA "true"> <!ELEMENT Instructions (Step)+> Element Type Declarations Attribute List Declarations

  13. Element Type Declarations • Element Name. • Content Model – Type of information • The attributes associated with it. Syntax: <!ELEMENT element_name (content_model)> Example: <!ELEMENT First_Name (#PCDATA)>

  14. Content Model • Subelements – list of subelements <!ELEMENT name (first_name, last_name)> • PCDATA – Text only (zero or more characters) <!ELEMENT element_name (#PCDATA)> • EMPTY – No content <!ELEMENT element_name EMPTY> • ANY – an undefined mixture of elements that have been declared in the DTD as well as character data. <!ELEMENT element_name ANY>

  15. Occurrences of Subelements • none: once and only once. • +: at least once or more. • ?: zero (never) or once. • *: optional; zero or more. • |: either. only one occurrence allowed.

  16. Common Errors in ETD • The element type declaration must be in CAPITALS. • The order of elements declared makes a big difference. • Did not use a right “validator”.

  17. Attribute List Declarations • The element to which the attribute is associated. • The name of the attribute. • The type of the attribute. • The default value. • Syntax: <!ATTLIST element_name attribute_name attribute_type attribute_defaults >

  18. String (CDATA) Enumerated |(one of specified values) ENTITY ENTITIES ID IDREF IDREFS NMTOLKEN NMTOLKENS NOTATION Attribute Types

  19. Attribute Default • Required – must supply a value. • Implied – The value is optional. • Fixed – fixed set of attributes. The values are included in the declaration itself. • Supplied – the DTD will supply the default value if it is not supply in the XML document.

  20. Entities Declaration • Entities are used to define shortcuts to commonly used text. • Internal Entity – the entity was declared within the XML document. • External Entity – the entity was declared in a DTD file.

  21. Internal Entity <?xml version=“1.0”?> <!DOCTYPE Company [<!ENTITY Company “XML Inc.”>]> <Company> <Name> &Company; </Name> <Address>Singapore</Address> </Company>

  22. External Entity Store the following statement in a file named “Entity.dtd”: <!ENTITY Company “XML Inc.”> Example: <?xml version=“1.0”?> <!DOCTYPE Company SYSTEM “Entity.dtd”> <Company> <Name> &Company; </Name> <Address>Singapore</Address> </Company>

  23. Thank You? Any Question?

  24. Programs/Systems • http://www.jclark.com/xml/ • http://www.jclark.com/xml/xt.html • Microsoft XML Notepad

More Related