AdvXML Lecture02 DTD

Embed Size (px)

Citation preview

  • 8/12/2019 AdvXML Lecture02 DTD

    1/22

    !"!

    $%&'()% *

    Advanced XML 1

  • 8/12/2019 AdvXML Lecture02 DTD

    2/22

    Explain DTD Create DTD:

    Declaring ElementsDeclaring Attributes

    Declaring Entities

    !"#$%&'$(

    Advanced XML 2

  • 8/12/2019 AdvXML Lecture02 DTD

    3/22

    A feature of SGML, inherited by XML. Contains the list of tags that specifies the

    grammatical structure of an XML document.

    DTD defines the way elements relate to one anotherwithin the documents tree structure, and specifiesthe attributes.

    DTD are of two types: An external DTD An internal DTD

    *+%,-$./ 012$ *$3.4&+. 5*0*6

    Advanced XML 3

  • 8/12/2019 AdvXML Lecture02 DTD

    4/22

    Provide an application independent way of sharingdata.

    Interchangedata between independent groups ofpeople.

    Can be used by the application to verifythat valid datahas been entered.

    Defines the legal building blocks of an XMLdocument.

    781 ,($ *0*

    Advanced XML 4

  • 8/12/2019 AdvXML Lecture02 DTD

    5/22

    type) >

    name attribute-nameattribute-type

    default-value>

    ]>

    DOCTYPE declaration

    ELEMENT declaration

    ATTRIBUTE

    declaration

    9/:,%/,:$ +; < *0*

    Advanced XML 5

  • 8/12/2019 AdvXML Lecture02 DTD

    6/22

    =./$:. *0*

    ]>

    Written directly in theXML document after the

    XML declaration.

    Writing the DTD withinthe DOCTYPE definitionis called as Wrapping.

    The file with the DTDand XML code has a .xmlextension.

    Advanced XML 6

  • 8/12/2019 AdvXML Lecture02 DTD

    7/22

    ?@/$:. *0*

    The DTD reference in the XML document file:

    The show.dtd file:

    Exists outside thecontent of a

    document.

    The DTD file hasa .dtdextension.

    Reference to theDTD file is added at

    the beginning of theXML file.

    Advanced XML 7

  • 8/12/2019 AdvXML Lecture02 DTD

    8/22

    XML elements are declared with an element declaration. Syntax

    Example

    *$%>

  • 8/12/2019 AdvXML Lecture02 DTD

    9/22

    EMPTY element content type specifies that theelement has no child elements or character data.

    Syntax

    Example

    Empty elements with attributes are possible:

    ?-2/1 ?>$-$./

    Advanced XML 9

  • 8/12/2019 AdvXML Lecture02 DTD

    10/22

    Syntax

    or

    Where:#PCDATA = element contains character data that is to be parsed

    ANY = element with any content

    ?>$-$./ B4/8 *

  • 8/12/2019 AdvXML Lecture02 DTD

    11/22

    Elements with one or more children are defined with the nameof the child element inside the parentheses.

    Syntax

    Example

    ?>$-$./ B4/8 C84>D ?>$-$./(

    Advanced XML 11

  • 8/12/2019 AdvXML Lecture02 DTD

    12/22

    Element occurrences

    Only one occurrence

    Minimum one

    occurrence

    element-name

    (child-name+)>

    Zero or more

    occurrences

    element-name

    (child-

    name*)>

    Zero or one occurrence

    !%%,::$.%$(

    Advanced XML 12

  • 8/12/2019 AdvXML Lecture02 DTD

    13/22

    9$E,$.%$

    Advanced XML 13

  • 8/12/2019 AdvXML Lecture02 DTD

    14/22

    C8+4%$

    Advanced XML 14

  • 8/12/2019 AdvXML Lecture02 DTD

    15/22

    Elements can have attributes. Syntax

    Example

    ]>

    *$%>

  • 8/12/2019 AdvXML Lecture02 DTD

    16/22

    Value Explanation

    CDATA The value is character data

    (eval|eval|..) The value must be an enumerated value

    ID The value is an unique id

    IDREF The value is the id of another element

    IDREFS The value is a list of other ids

    NMTOKEN The value is a valid XML name

    NMTOKENS The value is a list of valid XML names

    ENTITY The value is an entity

    ENTITIES The value is a list of entities

    NOTATION The value is a name of a notation

    xml: The value is predefined

    FG:4",/$ 5H,$ 012$6

    Advanced XML 16

  • 8/12/2019 AdvXML Lecture02 DTD

    17/22

    Value Explanation

    #DEFAULT The attribute has a default value.

    #REQUIREDThe attribute value must be included in the

    element.

    #IMPLIED The attribute does not have to be included.

    #FIXED The attribute value is fixed.

    FG:4",/$ 5*$;/ H,$6

    Advanced XML 17

  • 8/12/2019 AdvXML Lecture02 DTD

    18/22

    Entities that have their contents within the XMLdocument are called internal entities.

    Syntax

    Example

  • 8/12/2019 AdvXML Lecture02 DTD

    19/22

    Entities whose contents are found outside theXML document are called external entities.

    They are declared using the SYSTEM keyword. Syntax

    Example

    ?@/$:. ?.&/1 *$%>

  • 8/12/2019 AdvXML Lecture02 DTD

    20/22

    A well-formed document is one that conforms to the basicrules of XML.

    A valid document is well formed and is also validated againsta DTD.

    The DTD specifies the grammatical structure of an XMLdocument, by allowing XML parsers to understand andinterpret the documents contents.

    The use of the SYSTEM keyword indicates to the parser thatthis is an external declaration, and that the set of rules for this

    XML document can be found in a specified file. EMPTY element content type specifies that the element has

    no child elements or character data.

    9,--

  • 8/12/2019 AdvXML Lecture02 DTD

    21/22

    #CDATA means that the element contains character data that is notto be parsed by a parser.

    #PCDATA means that the element contains data that is to be parsed

    by a parser.

    Specifying a default value for an attribute in the DTD ensures thatthe attribute will get a value, even if the author of the XML

    document does not include it.

    Specifying the value of an attribute as Implied means that theparticular attribute is not mandatory and can be specified in theXML document.

    Specifying the value of an attribute as Required means that theparticular attribute is mandatory (that is, its value must be provided

    in the XML document).

    9,--

  • 8/12/2019 AdvXML Lecture02 DTD

    22/22

    ID is the identifier type, and should be unique. Thisattribute value is used to search for a particular instance ofan element. Each element can only have one attribute of typeID.

    A DTD can be either External or Internal.

    Entities allow us to create an alias to some large piece oftext, so that, in the document, the same piece of text can bereferred to, simply by referring to the alias.

    Namespaces allow us to combine documents from differentsources, and be able to identify which elements or attributescome from which source.

    9,--