1 / 25

Document Type definition

Document Type definition. DTD. Structural Analysis and DTD. Structural Analyses and DTD What is DTD Ex: phonebook.dtd Ex: phonebook.xml Parts of XML Document Producing XML Document XML Browsers Ex phonebook.xsl DTD Planning XML: Separators XML: Comments and Naming XML: Elelemnts

anoush
Download Presentation

Document 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. Document Type definition DTD Structured Documents KA

  2. Structural Analysis and DTD • Structural Analyses and DTD • What is DTD • Ex: phonebook.dtd • Ex: phonebook.xml • Parts of XML Document • Producing XML Document • XML Browsers • Ex phonebook.xsl • DTD Planning • XML: Separators • XML: Comments and Naming • XML: Elelemnts • XML: Order of elements • Ex: Letter • Ex: Letter b • Ex: letter c • DTD: Building Blocks • DTD: Elements • XML tags • DTD: Attributes • Types of Attribute • Attribute Defaults • DTD: Predefined Entities • DTD: Own Entities • DTD: PCDATA / CDATA Structured Documents KA

  3. What is a DTD • DTD = Document Type Definition • definition of the document class • DTD descripes the logical elements, their order and content • DTD can be created from the structure diagram Structured Documents KA

  4. Example phonebook.dtd <!-- There can be many persons --> <!ELEMENT phonebook (person*)> <!ATTLIST phonebook company CDATA #REQUIRED> <!ELEMENT person (firstname, surname,address,phone )> <!ELEMENT address (street,postalcode, postoffice)> <!ELEMENT phone (homenumber, mobile)> <!ATTLIST phone confidential (yes | no ) "no"> <!ELEMENT firstname (#PCDATA)> <!ELEMENT surname (#PCDATA)> <!ELEMENT street (#PCDATA)> <!ELEMENT postalcode (#PCDATA)> <!ELEMENT postoffice (#PCDATA)> <!ELEMENT homenumber (#PCDATA)> <!ELEMENT mobile (#PCDATA)> Structured Documents KA

  5. Example phonebook. xml <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="phonebook.xsl"?> <!DOCTYPE phonebook SYSTEM "phonebook.dtd"> <!-- DOCTYPE root-element SYSTEM "filename"--> <phonebook company = "Gurus ltd"> <person> <firstname>Michael</firstname> <surname>Schumacher</surname> <address> <street>Nelikkoratsu 2 A56</street> <postalcode>01234</postalcode> <postoffice>Heinola</postoffice> </address> <phone> <homenumber>04 11223 344</homenumber> …… Structured Documents KA

  6. Parts of an XML Document • A XML document itself consist of: • XML declaration (can be missing) • Document Type Definition (DTD can be missing) • Root element(eg. <mail> • Document instance(representative of the document class) • XML declaration informs the XML prosessing system about the version and the character set e.g. • DTD can be written directly into a document itself or into another document Structured Documents KA

  7. Producing an XML Document dbase dbase XML editor simple editor XML + DTD • XML Spy • XMetal • Eclipse conversion Intelligent OCR Structured doc Paper doc Structured Documents KA

  8. Example phonebook.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0” xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1>Phonebook</h1> <h2>Company <xsl:value-of select="@company"> </h2> <h4> ….. Structured Documents KA

  9. DTD Planning • Define application area (firm, department …) • Define strategy of using the DTD • Why to do the DTD? • How DTD is applied? • Priority of functionality? • Access criterias? • Sorting/Calculation criterias • Define the users • Name the DTD • Define the logical elements of the document class • Structure analyzes • Name the elements • Element vs. attribute Structured Documents KA

  10. XML: Separatos • <! < </ > /> • Used to separate the information and the markup • E.g. <h1> Header</h1> Structured Documents KA

  11. XML: Comments and Naming • A comment is defined • <! - - This is a comment - - > • XML name consist of the following chars: • 1. char a-z, A-Z • 2-n. char a-z, A-Z, 0-9,.,- • NO tab or whitespace • XML names are CASE sensitive Structured Documents KA

  12. XML: Elements • Element format <to> • Element ending </to> • Element is defined in the DTD <!ELEMENT to (#PCDATA) > • Element can include other elements <!ELEMENT letter (to, from, p*)> • The part within the parenthis is called the model group. • Element can be text, #PCDATA or include other elements. Structured Documents KA

  13. XML: Order of Elements • Elements in sequence are separated with a comma (,) • 0,1 or n times appearing elements with (*) • 1 or n times appearing elements with (+) • Alternative elements with a pipe (|) • 0 or 1 time appearing element with a question mark (?) Structured Documents KA

  14. Example: letter letter.dtd <!ELEMENT letter (from, to, p*, sign)> <!ELEMENT from (#PCDATA) > <!ELEMENT to (#PCDATA) > <!ELEMENT p (#PCDATA) > <!ELEMENT sign (#PCDATA) > letter.xml <?xml version=“1.0”?> <!DOCTYPE letter SYSTEM ”letter.dtd"> <letter> <from>Seija R.</from> <to>Kake A.</to> <p>Perjantaina on tiimipalaveri</p> <sign>Seija R.</sign> </letter> Structured Documents KA

  15. Example: letter b letterb.dtd <!ELEMENT LETTER (HEADER, BODY, END)> <!ELEMENT HEADER (TO, FROM, SUBJECT)> <!ELEMENT BODY (P*) > <!ELEMENT END (SIGN*) > <!ELEMENT FROM (#PCDATA) > <!ELEMENT TO (#PCDATA) > <!ELEMENT SUBJECT (#PCDATA) > <!ELEMENT P (#PCDATA) > <!ELEMENT SIGN (#PCDATA) > letterb.xml <?xml version=“1.0”?> <!DOCTYPE LETTER SYSTEM ”letterb.dtd"> <LETTER><HEADER> <FROM>Seija R.</FROM> <TO>Kake A.</TO> <SUBJECT>Tiimipalaveri</SUBJECT> </HEADER> <BODY> <P>Perjantaina on tiimipalaveri</P> </BODY> <END> <SIGN>Seija R.</SIGN> <SIGN>Erkki R.</SIGN> </END> </LETTER> Structured Documents KA

  16. Example: letter c letterc.dtd <!ELEMENT LETTER (HEADER, BODY, END)> <!ELEMENT HEADER (((FROM,TO+) | (TO+, FROM)), SUBJECT)> <!ELEMENT BODY (P*) > <!ELEMENT END (SIGN*) > <!ELEMENT FROM (#PCDATA) > <!ELEMENT TO (#PCDATA) > <!ELEMENT SUBJECT (#PCDATA) > <!ELEMENT P (#PCDATA) > <!ELEMENT SIGN (#PCDATA) > Structured Documents KA

  17. DTD Building Blocks Seen from a DTD point of view, all XML documents (and HTML documents) are made up by the following simple building blocks: • Elements • Tags • Attributes • Entities • PCDATA = parseable character data • CDATA Structured Documents KA

  18. DTD: Elements Elements are the main building blocks of both XML and XHTML documents. Examples of XHTML elements are "body" and "table". Examples of XML elements could be "note" and "message". Elements can contain text, other elements, or be empty. Examples of empty HTML elements are "hr", "br" and "img". Structured Documents KA

  19. XML: Tags Tags are used to markup elements. A starting tag like <element_name> marks up the beginning of an element, and an ending tag like </element_name>  marks up the end of an element. body element marked up with body tags: <body>body text in between</body>.  message element marked up with message tags: <message>some message in between</message> Structured Documents KA

  20. DTD: Attributes Attributes provide extra information about elements. Attributes are always placed inside the starting tag of an element. Attributes always come in name/value pairs. The following "img" element has additional information about a source file: <img src="computer.gif" /> The name of the element is "img". The name of the attribute is "src". The value of the attribute is "computer.gif". Since the element itself is empty it is closed by a " /". DTD: <!ATTLIST DRINK amount CDATA> .xml: <DRINK amount=”4 dl"> Structured Documents KA

  21. Type Meaning CDATA Character data (string) ID IDREF IDREFS Name unique within a given document Reference to some element bearing an ID attribute Series of IDREFs delimited with white space ENTITY ENTITIES Name of predefined external entity Series of entity names delimited by white space NMTOKEN A name NOTATION Accepts one of a series of explicitly user-defined values that the attribute can take on Types of Attribute dtd: <!ATTLIST someEl someText CDATA #IMPLIED> xml:< someEl someText =”Pisa is something”> dtd: <!ATTLIST Person ssn ID #REQUIRED> xml:< Person ssn = ”22-11-20033”> … </Person> Structured Documents KA

  22. Value Explanation value The attributes default value #DEFAULT value The attributes default value #REQUIRED The attribute value must be included in the element #IMPLIED The attribute does not have to be included #FIXED value The attribute value is fixed Attribute Defaults <!ATTLIST catalog music (pop | classic | unqualified ) #REQUIRED> Structured Documents KA

  23. DTD: Predefined Entities Entities are variables used to define common text. Entity references are references to entities. Most of you will know the HTML entity reference: "&nbsp;". This "no-breaking-space" entity is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser. The following entities are predefined in XML: Entity References Character &lt; < &gt; > &amp; & &quot; " &apos; ' Structured Documents KA

  24. DTD: Own Entities <!ENTITY EVTEK ”Espoo Vantaa Instituite of Technology"> <!ENTITY deg ”&#176;”> Every where in XML file the note &EVTEK; is replaced with string Espoo Vantaa Instituite of Technology and <joke>It is 45 &deg; now in Turkey </joke> is replaced with string It is 45° now in Turkey Structured Documents KA

  25. DTD: PCDATA / CDATA PCDATA means parsed character data. PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.  CDATA also means character data. CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded. Structured Documents KA

More Related