Xml 2
This presentation is the property of its rightful owner.
Sponsored Links
1 / 22

XML (2) PowerPoint PPT Presentation


  • 37 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Xml 2

XML (2)

DTD

Sungchul Hong


Xml 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>


Document type definition

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.


Document type declarations

Document Type Declarations

  • <! DOCTYPE JU:LunchMenu SYSTEM http://catering.com/menus/lunch/Menu.DTD>

  • <!DOCTYPE JU:LunchMenu PUBLIC “/lunch/Menu.DTD”>


Internal dtd subset

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.


Xml 2

<?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>


External dtd subset

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”>


Xml 2

<?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>


Elements

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.


Elements1

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)>


Elements syntax

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.


Example

Example

<!ELEMENT DOCUMENT (TITLE,AUTHOR+,SUMMARY*,NOTE?)>

<!ELEMENT User (Name, Email | Phone))>

<!ELEMENT Blah (A, (B?, C)*, D+, (E|F)>


Attributes syntax

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.


Attribute types

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>


Attribute types1

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>


Attribute types2

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”/>


Attribute types3

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”/>


Enumerated values

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>


Notation

NOTATION

  • NOTATION- Identify the format of external data items that we wish to use with our XML document

  • <!NOTATION gif SYSTM “imageviewer.exe”>


Entities

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


Xml 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>


Problems with dtd

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


  • Login