Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Document Type Definitions and the Document object model.

Similar presentations


Presentation on theme: "XML Document Type Definitions and the Document object model."— Presentation transcript:

1 XML Document Type Definitions and the Document object model

2 Document Type Definition(DTD) A DTD defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes A DTD can be declared inside an XML file or as an external file

3 DTD as an external file XML document Jimmy Joey Message Hello The DOCTYPE definition defines the external DTD

4 The DTD The file note.dtd contains the DTD. The content of the file are as follows Ordering matters here PCDATA stands for parsed character data. This data is parsed by the XML parser The # is a reserved word indicator

5 DTD inside XML document <!DOCTYPE note [ ]> Jimmy Joey Message Hello

6 Why use a DTD? An XML file can carry a description of its own format If independent groups of people agree to use a standard DTD(e.g the DTD for MathML) then these groups can interchange data freely Your application can use a DTD to verify data from an external source You can verify your own data with a DTD

7 DTD Structure 1 A DTD is composed of a number of declarations Each declaration conforms to the markup declaration format The components of a DTD are: –Elements –Attributes –Entities –PCDATA –CDATA

8 DTD Structure 2(Elements) Declaring elements e.g. Elements with children Declaring exactly one occurrence of an element Declaring at least one occurrence of an element Declaring zero or more occurrences of an element Declaring zero or one occurrence of an element

9 DTD Structure 3(Elements) Declaring either/or content Declaring mixed content

10 DTD Structure 4 (Attributes) Declaring Attributes Recall from the recipe.xml example from previous lecture Flour

11 DTD Structure 5 (Attributes) There are other attribute types but we will not consider them here Alternative default values –#IMPLIED –#FIXED value

12 Sample DTDs The following DTDs describe the data in the XML files considered from the previous lecture. These files are provided here for completeness

13 XML file: Book.xml The XML Companion Neil Bradley $99.00 0201674866

14 DTD: book.dtd

15 XML file: article.xml XML in Action April 2, 2007 Joe Bloggs Example of XML XML is a Markup Language that allows its users to specify their own tags

16 DTD: article.dtd

17 XML file: recipe.xml Basic bread Flour Yeast Water Salt Mix all ingredients together, and knead thoroughly. Cover with a cloth, and leave for one hour in warm room. Knead again, place in a tin, and then bake in the oven.

18 DTD: recipe.dtd

19 Document Object Model(DOM) The XML DOM defines a standard way for accessing and manipulating XML documents The DOM presents an XML document as a tree structure. Everything in a XML document is treated as a node in the DOM

20


Download ppt "XML Document Type Definitions and the Document object model."

Similar presentations


Ads by Google