3.1 Creating a Basic XML Document Containing a DTD

Overview

This chapter covers the interaction between an XML document and a basic road map for the structure of that XML document. Here you will learn about Document Type Definitions (DTDs) and the rules for creating them. You will be presented with an exercise to create a DTD for the FileMaker Pro theme files, which are used by the New Layout/Report assistant. The exercise is provided to further explain how XML and DTDs work together. Finally, the differences between DTD and schema formats are discussed.

With DTDs, you can define the type of document and define what makes it valid based on the allowable elements and content. Being valid is a good reason to create these definitions, although it is not a requirement for well-formed XML documents. With a Document Type Definition, XML documents are not only valid to the XML processors, but also to an industry that wants to share information and maintain standards for document exchange.

Document Type Definitions can be listed in the XML document or referenced by a link to an external document. Listings 3.1 and 3.2 show examples of the internal and external DTDs. External references can use the same DTD for multiple documents. In this way, a company could keep all documents valid with a single external Document Type Definition. Like the XML it defines, external DTDs can be reused.

Listing 3.1: XML document with an internal DTD

start example
 <?xml version="1.0" standalone="yes" ?> <!DOCTYPE myDoc [ <!ELEMENT myDoc (head, main)> <!ELEMENT head (#PCDATA)> <!ELEMENT main (para)> <!ELEMENT para (#PCDATA)> ]> <myDoc>          <head>This is the first element of my document</head>          <main>                  <para>Now I can add content.</para>                  <para>Each line is another child of the main element</para>          </main> </myDoc>
end example

Listing 3.2: XML document with external DTD

start example
 "mydoc.xml" <?xml version="1.0" standalone="no" ?> <!DOCTYPE myDoc SYSTEM "myDoc.dtd"> <myDoc>          <head>This is the first element of my document</head>          <main>                  <para>Now I can add content.</para>                  <para>Each line is another child of the main element</para>          </main> </myDoc> "myDoc.dtd" <!DOCTYPE myDoc [ <!ELEMENT myDoc (head, main)> <!ELEMENT head (#PCDATA)> <!ELEMENT main (para)> <!ELEMENT para (#PCDATA)> ]>
end example

There are variations on the Document Type Definition. The World Wide Web Consortium adopted XML Schema as a recommendation. These are more complete in describing a document. Schemas, or XML Schema Documents (XSD), will be discussed at the end of this chapter. FileMaker Pro uses and produces DTDs, so these are presented here and in Chapter 4. Current DTD specifications are defined in "Extensible Markup Language (XML) 1.0 (Second Edition)", http://www.w3.org/TR/REC-xml.



Filemaker Pro 6 Developer's Guide to XML(s)XSL
FileMaker Pro 6 Developers Guide to XML/XSL (Wordware Library for FileMaker)
ISBN: 155622043X
EAN: 2147483647
Year: 2003
Pages: 100
Authors: Beverly Voth

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net