1 / 22

XML (2)

XML (2). DTD Sungchul Hong. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE simple [ <!ELEMENT DOCUMENT (#PCDATA)> <!ATTLIST DOCUMENT trackNum CDATA #REQUIRED secLevel (unclassified|classified) "unclassified"> <!ENTITY Description "This is a very simple

Télécharger la présentation

XML (2)

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. XML (2) DTD Sungchul Hong

  2. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE simple [ <!ELEMENT DOCUMENT (#PCDATA)> <!ATTLIST DOCUMENT trackNum CDATA #REQUIRED secLevel (unclassified|classified) "unclassified"> <!ENTITY Description "This is a very simple sample document."> ]> <DOCUMENT trackNum="1234">This is an entity inside an element:&Description; </DOCUMENT>

  3. Document Type Definition • A DTD is used to validate an XML document. • Only one DTD per document • Document type declaration • <!DOCTYPE name […]> • XML documents • Well formed documents • Document must comply with the XML specification. • Valid documents • A valid document is a document that has a DTD and follows the rule laid out in that DTD.

  4. Document Type Declarations • <! DOCTYPE JU:LunchMenu SYSTEM http://catering.com/menus/lunch/Menu.DTD> • <!DOCTYPE JU:LunchMenu PUBLIC “/lunch/Menu.DTD”>

  5. Internal DTD Subset • A DTD can be declared internal to the XML document • Internal subsets are parsed before external subsets • Internal declarations that match external declarations will override the corresponding declarations.

  6. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE simple [ <!ELEMENT DOCUMENT (TITLE,AUTHOR+,SUMMARY*,NOTE?)> <!ATTLIST DOCUMENT trackNum CDATA #REQUIRED secLevel (unclassified|classified) "unclassified"> <!ELEMENT TITLE (#PCDATA)> <!ELEMENT AUTHOR (#PCDATA)> <!ELEMENT SUMMARY (#PCDATA)> <!ENTITY Description "This is a very simple sample document."> ]> <DOCUMENT trackNum="1234"> <TITLE>Sample Document</TITLE> <AUTHOR>Simon St.Laurent</AUTHOR> <SUMMARY>This is an entity inside an element:&Description; </SUMMARY></DOCUMENT>

  7. External DTD Subset • The Document Type Declaration will now provide a URL and either a system or public identifier • Provides more flexibility than internal DTD subsets • <! DOCTYPE JU:LunchMenu SYSTEM http://catering.com/menus/lunch/Menu.DTD> • <!DOCTYPE JU:LunchMenu PUBLIC “/lunch/Menu.DTD”>

  8. <?xml version="1.0" standalone="no""UTF-8"?> <!DOCTYPE SIMPLE SYSTEM "http://127.0.0.1/simple.dtd"> <SIMPLE> <DOCUMENT trackNum="1234"> <TITLE>Sample Document</TITLE> <AUTHOR><FIRSTNAME>Simon</FIRSTNAME> <LASTNAME>St.Laurent</LASTNAME> <COMPANY>XML Mania</COMPANY> </AUTHOR> <SUMMARY>This is an entity inside an element:&Description; </SUMMARY> </DOCUMENT> </SIMPLE>

  9. Elements • <!ELEMENT name data> • <!ELEMENT DOCUMENT (TITLE,AUTHOR+,SUMMARY*,NOTE?)> • Declares what elements are legal, what order they should appear in and the number of elements • Data can be one of five types: Empty, Elements-only, Characters-only, any and mixed.

  10. Elements • Empty: the corresponding element cannot contain either text or other elements • <!ELEMENT price EMPTY> • Element-only: the corresponding element can only contain other elements, no text. • <!ELEMENT person (name, address, tel)> • Characters-only: The corresponding element can contain only text • <!ELEMENT bookinfo (#PCDATA) > • Any: the corresponding element can include any of previous three types • <!ELEMENT other ANY> • Mixed: the corresponding element must have both elements and text • <!ELEMENT mixedup (e1, e2) (#PCDATA)>

  11. Elements Syntax • Content model • ( ): substructure • , : strict ordering • | : choice • ?: optional • *: zero or more of a particular item can appear. • +: The plus-sign (+) denotes that one or more of a particular item can appear.

  12. Example <!ELEMENT DOCUMENT (TITLE,AUTHOR+,SUMMARY*,NOTE?)> <!ELEMENT User (Name, Email | Phone))> <!ELEMENT Blah (A, (B?, C)*, D+, (E|F)>

  13. Attributes Syntax • A DTD defines attributes with the <!ATTLIST …> declaration. • <!ATTLIST element attribute CDATA #required> • #REQUIRED-the attribute must appear with this element. • #IMLIED- the attribute may appear with this element. • #FIXED default value – the attribute must always have the default value. If it does not appear explicitly, it is assumed. • Default value – the attribute may appear with the default or can have another value.

  14. Attribute Types • CDATA – Character data. Used if an attribute value is only plain text. • <!ATTLIST Order order_num CDATA #REQUIRED> • <order order_num = “123abc”> … </order>

  15. Attribute Types • ID – unique name within a document used to uniquely identify an element. • <!ATTLIST Order order_num ID #REQUIRED> • <Order order_num = “123abc”> .. </order> • <order order_num = “456def”> …</order>

  16. Attribute Types • IDREF- A reference to an element with an ID, allowing for links to b created within documents. • <!ATTLIST Order order_num ID #REQUIRED> • <!ATTLIST ClosedOrder order_ref IDREF #REQUIRED> • <Order order_num = “123abc”>… </Order> • <ClosedOrder order_ref = “123abc”/>

  17. Attribute Types • IDREFS – Series of references to elements with corresponding Ids • <!ELEMENT ClosedOrders EMPTY> • <!ATTLIST Order order_num ID #REQUIRED> • <!ATTLIST ClosedOrders order_ref IDREFS #REQUIRED> • <Order order_num = “123abc”>… </Order> • <Order order_num = “456def”>… </Order> • <ClosedOrders order_ref = “123abc 456def”/>

  18. Enumerated Values • Enumerated values are defined with not type definition. • A parenthetical sequence of legal values is given instead • Do not use quotation marks and remember the values are case sensitive • <!ATTLIST JU:Dessert type (regular | lowfat | sugar-free) #REQUIRED> • <JU:Dessert type = “lowfat”>Cheescake</JU:Dessert>

  19. NOTATION • NOTATION- Identify the format of external data items that we wish to use with our XML document • <!NOTATION gif SYSTM “imageviewer.exe”>

  20. Entities • Entities allow you t declare content and reference it anytime you need it within a document • Entities are like an alias to some content • Predefined entities &lt, &gt, &amp, &apos, &quote

  21. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE simple [ <!ELEMENT DOCUMENT (#PCDATA)> <!ATTLIST DOCUMENT trackNum CDATA #REQUIRED secLevel (unclassified|classified) "unclassified"> <!ENTITY Description "This is a very simple sample document."> ]> <DOCUMENT trackNum="1234">This is an entity inside an element:&Description; </DOCUMENT>

  22. Problems With DTD • DTD use a non-XML syntax. • There is no way to type information like numbers • DTDs do not allow merging of documents • XML Schema

More Related