Professional Documents
Culture Documents
SOA - WS-Topic 3-I
SOA - WS-Topic 3-I
SOA - WS-Topic 3-I
Dr.Chamara
Dept. of ICT, Faculty of Technology
University of Sri Jayewardenepura
Usage
With a DTD, independent groups of people can agree on
a standard DTD for interchanging data.
An application can use a DTD to verify that XML data is
valid.
INTERNAL DTD DECLARATION: EXAMPLE
INTERNAL DTD DECLARATION: EXAMPLE
The DTD in the example can be explained like this:
!DOCTYPE address defines that the root element of this document is
address.
!ELEMENT address defines that the address element contains five
elements: name, no, street, city and country
!ELEMENT name defines the name element to be of type #PCDATA
!ELEMENT no defines the no element to be of type #PCDATA
!ELEMENT street defines the street element to be of type #PCDATA
!ELEMENT city defines the city element to be of type #PCDATA
!ELEMENT country defines the country element to be of type
#PCDATA
EXTERNAL DTD DECLARATION
If the DTD is declared in an external file, it should be
wrapped in a DOCTYPE definition with the following
syntax:
EXTERNAL DTD DECLARATION: EXAMPLE
This is the same XML document as before, but with an
external DTD.
EXTERNAL DTD DECLARATION: EXAMPLE
The file “address.dtd” contains the following DTD:
DECLARING ELEMENTS
In a DTD, elements are declared with an element
declaration with the following syntax:
or
EMPTY ELEMENTS
Empty elements are declared with the category keyword
EMPTY.
Example:
XML example:
ELEMENTS WITH PARSED CHARACTER
DATA
Elements with only parsed character data are declared
with #PCDATA inside parentheses.
Example:
PCDATA VS CDATA
PCDATA
PCDATA means parsed character data.
Think of character data as the text found between the start tag and
the end tag of an XML element.
PCDATA is text that WILL be parsed by a parser. The text will be
examined by the parser for entities and markup.
CDATA
Character Data
All text in an XML document will be parsed by the parser, but
CDATA text will be ignored by the parser. Tags inside the text will
NOT be treated as markup.
ELEMENTS WITH ANY CONTENTS
Elements declared with the category keyword ANY, can
contain any combination of parsable data.
Example:
ELEMENTS WITH CHILDREN
Elements with one or more children are declared with the
name of the children elements inside parentheses.
Example:
Example:
The child element street must occur once, and only once
inside the address element.
DECLARING MINIMUM ONE OCCURRENCE
OF AN ELEMENT
Syntax:
Example:
The + sign declares that the child element street must occur
one or more times inside the address element.
DECLARING ZERO OR MORE
OCCURRENCES OF AN ELEMENT
Syntax:
Example:
The * sign declares that the child element street can occur
zero or more times inside the address element.
DECLARING ZERO OR ONE OCCURRENCES
OF AN ELEMENT
Syntax:
Example:
The ? sign declares that the child element street can occur
zero or one time inside the address element.
DECLARING EITHER/OR CONTENT
Example:
XML example:
Valid XML:
DTD:
<!ATTLIST person number CDATA #REQUIRED>
DTD:
<!ATTLIST contact fax CDATA #IMPLIED>
DTD:
<!ATTLIST sender company CDATA #FIXED "Microsoft">
DTD:
<!ATTLIST payment type (check|cash) "cash">