·  XML – DTD – Examples - Simple

 

- Info:

  - This tutorial shows different examples of using DTD elements,

 

- Element with textual data:

  

<!ELEMENT city   (#PCDATA)>

<city>New York</city>

 

- Element with no data:

  

<!ELEMENT br     EMPTY>

<br/>

 

- Element must containg exactly one child "mobile":

  

<!ELEMENT phone  (mobile) >

<!ELEMENT mobile (#PCDATA)>

 

<phone>

  <mobile>09145644</mobile>

</phone>

 

- Element must containg exactly one or more child "mobile":

  

<!ELEMENT phone  (mobile+)>

<!ELEMENT mobile (#PCDATA)>

 

<phone>

  <mobile>09145644</mobile>

</phone>

 

<phone>

  <mobile>09145641</mobile>

  <mobile>09145642</mobile>

  <mobile>09145643</mobile>

</phone>

 

- Element must containg exactly zero or more child "mobile":

  

<!ELEMENT phone  (mobile*)>

<!ELEMENT mobile (#PCDATA)>

 

<phone>

</phone>

 

<phone>

  <mobile>09145644</mobile>

</phone>

 

<phone>

  <mobile>09145641</mobile>

  <mobile>09145642</mobile>

  <mobile>09145643</mobile>

</phone>

 

- Element must containg exactly zero or one child "mobile":

  

<!ELEMENT phone  (mobile?)>

<!ELEMENT mobile (#PCDATA)>

 

<phone>

</phone>

 

<phone>

  <mobile>09145644</mobile>

</phone>

 

- Element must containg exactly one or more child "to" and exactly one child "from":

  

<!ELEMENT mail  (to+,from)>

<!ELEMENT to    (#PCDATA) >

<!ELEMENT from  (#PCDATA) >

 

<mail>

  <to>lion@zoo</to>

  <from>monkey@jungle</from>

</mail>

 

<mail>

  <to>lion@zoo</to>

  <to>gepard@zoo</to>

  <to>turtle@zoo</to>

  <from>monkey@jungle</from>

</mail>

 

- Element must contain either one child "dead" or one child "alive":

  

<!ELEMENT human (dead|alive)>

<!ELEMENT dead  (#PCDATA)   >

<!ELEMENT alive (#PCDATA)   >

 

<human>

  <dead>John</dead>

</human>

 

<human>

  <alive>Jack</alive>

</human>


- Attribute role is required and can have value mother or father:

  

<!ELEMENT parent (#PCDATA)>

  <!ATTLIST parent role (mother | father) #required>

 

<parent role=mother>

  Hello children

</parent>

 

<parent role=father>

  Hello children 

</parent>

 

- Attribute radius is of type CDATA and have 0 as defult values:

  

<!ELEMENT circle EMPTY>

  <!ATTLIST cricle radius CDATA "0">

 

<circle radius="100"> 

</circle>

 

<circle> 

</circle >

 

- Attribute company has fixed value "Microsoft":

  

<!ELEMENT sender EMPTY>

  <!ATTLIST sender company CDATA #FIXED "Microsoft">

 

<sender company="Microsoft">

</sender >