1 / 13

Valid XML documents (contd.)

Valid XML documents (contd.). For example, if we wanted to turn the example well-formed XML document we have just seen into a valid document, we would insert a line which would look like <!DOCTYPE people someDTDspec >

fell
Télécharger la présentation

Valid XML documents (contd.)

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. Valid XML documents (contd.) • For example, if we wanted to turn the example well-formed XML document we have just seen into a valid document, we would insert a line which would look like <!DOCTYPE people someDTDspec> where someDTDspec would specify what rules must be followed by a validpeople element • Although a doctype statement may directly contain an internal DTD, we will consider only the cases where a doctype statement refers to an external DTD, because these are the most useful

  2. DOCTYPEs referring to external DTDs • A doctype statement which refers to an external DTD has one of two formats: <!DOCTYPE nameOfRootElementSYSTEM “fileNameAndPath” > <!DOCTYPE nameOfRootElement PUBLIC “fpi” ”url” > • In the first format, <!DOCTYPE nameOfRootElementSYSTEM “fileNameAndPath” > the keyword SYSTEM says that the external DTD is on the local machine and fileNameAndPath says where to find it • In the second format, <!DOCTYPE nameOfRootElementPUBLIC “fpi” ”url” > the keyword PUBLIC says that the external DTD is publicly available on the Internet, the fpi (Formal Public Identifier) gives its formal name and the url says where it can be found

  3. Example DOCTYPEs referring to external DTDs • The doctype statement <!DOCTYPE people SYSTEM “myFirstDTD.dtd” > says that the external DTD is on the local machine, in a file called myFirstDTD.dtd • The doctype statement <!DOCTYPE peoplePUBLIC “-//UCC//DTD PEOPLE v1.0//EN” ”student.cs.ucc.ie/path/to/myFirstDTD.dtd” > says that the external DTD is publicly available on the Internet, gives it a formal name which should be used by everybody who wants to refer to it, and says where it can be found

  4. Formal Public Identifiers • We will be focussing on system DTDs but some of you may be wondering about the format of FPIs like -//UCC//DTD PEOPLE v1.0//EN • This format is actually defined by an ISO standard and FPIs like this can be registered with organizations which are authorized by the ISO Council to act as FPI registrars • The format is • the-(which could also be a+ ) indicates whether/not the organization name which follows is ISO-registered; UCC is not • UCC is an OwnerID, the name of the organization which owns and maintains the document identified by the FPI • DTD is a Public Text Class, a keyword identifying the type of doc • PEOPLE v1.0 is a unique descriptive name for the document • EN is the Public Text Language, in which the doc is written

  5. Formal Public Identifiers (contd.) • For example, this is the formal public identifier for one version of the HTML 4 specification: -//W3C//DTD HTML 4.01//EN • theW3C is not an ISO-registered organization • the HTML4 specification is a DTD • HTML 4.01 is a unique descriptive name • EN says that the specification is written in English

  6. XML document which claims to be valid <?xml version="1.0”?> <!DOCTYPE poem SYSTEM “poem.dtd”> <poem> <title>The Daffodils</title> <poet>William Wordsworth</poet> <verse> <line>I wandered lonely as a cloud</line> <line>That floats on high o’er vales and hills</line> <line>When all at once I saw a crowd</line> <line>A host of golden daffodils</line> </verse> <verse> <line>Something something something</line> <line> ... </line> </verse> </poem>

  7. Another XML document claiming to be valid <?xml version="1.0”?> <!DOCTYPE people SYSTEM “personnel.dtd”> <people> <man> <name> Ray Burke </name> <numberOfWives> 1 </numberOfWives> </man> <woman> <name> Margaret Thatcher </name> <age> 75 </age> </woman> </people>

  8. Document Type Definitions • A DTD defines the syntax rules for an application-specific type of XML-documents. • A DTD describes the root element that may appear in a valid document and, in doing so, also describes the kinds of children elements that the root element may possess • A DTD must contain element type declarations, statements which have the following general format: <!ELEMENTelementName contentModel> • In addition, a DTD may contain a range of other types of statement, only one of which we will cover here, attribute declarations, statements which are used to define the attributes which elements may have.

  9. Element Type Declarations • An element type declaration is a statements which has the following general format: <!ELEMENT elementName( contentModel )> where contentModel describes the content (if any) that may or must exist between the start tag and the closing tag (if any) of the element whose name is elementName

  10. Empty Elements • Empty elements are declared using the keyword EMPTY inside the parentheses <!ELEMENT element-name (EMPTY)> • Example: <!ELEMENT trustworthy (EMPTY) > which declares an element which only has a start tag and which, unless it has some attribute(s), must be written as <trustworthy/>

  11. Elements with Character content • Elements that contain character data are declared as follows: <!ELEMENT element-name (#PCDATA)> where #PCDATA stands for “parsed character data” • Example: <!ELEMENT month (#PCDATA)> This element declaration would be satisfied by the following text in an XML file <month>January</month>

  12. Elements with element content • Elements that contain only children elements are declared as follows: <!ELEMENT element-name(child-element-name)> or <!ELEMENT element-name (child-name1, child-name2, ...)> • Example <!ELEMENT country (position)> which specifies that a country element contains exactly one child element, a position element: <country> <position> ..... </position> </country>

  13. Elements with element content (contd.) • Example <!ELEMENT memorandum (sender,recipient,message)> which specifies that a memorandum element contains a sender element, followed by a recipient element, followed by a message element • When a sequence of children elements is declared, as above, the children must appear in exactly the same sequence in conforming XML documents: <memorandum> <sender> ..... </sender> <recipient> ...... </recipient> <message> ...... </message> </memorandum>

More Related