tanszek:oktatas:techcomm:dtd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tanszek:oktatas:techcomm:dtd [2024/10/07 17:40] kneheztanszek:oktatas:techcomm:dtd [2024/10/07 17:57] (current) – [Complex DTD Example for a Hypothetical Mail Processing System] knehez
Line 70: Line 70:
  
 <sxh> <sxh>
-<!DOCTYPE datastorage [+<!DOCTYPE datastore [
     <!ELEMENT datastorage  (pendrive | SSD)>     <!ELEMENT datastorage  (pendrive | SSD)>
     <!ELEMENT pendrive ( #PCDATA ) >     <!ELEMENT pendrive ( #PCDATA ) >
Line 90: Line 90:
 | ''?''    | The element appears zero or one time. | | ''?''    | The element appears zero or one time. |
  
-=== Example: A music CD contains **tracks**: ===+==== Example: A music CD contains **tracks**: ====
  
 <sxh> <sxh>
Line 105: Line 105:
 </CD> </CD>
 </sxh> </sxh>
 +----
 +==== Example: An album has at least one title, followed by at least one **track title** and **duration**: ====
  
-#### Example: An album has at least one title, followed by at least one **track title** and **duration**: +<sxh> 
- +<!DOCTYPE datastorage 
-```dtd +    <!ELEMENT album (title+, (tracktitleduration)+)> 
-<!DOCTYPE adathordozo +    <!ELEMENT title ( #PCDATA ) > 
-    <!ELEMENT album (cim+, (dalcimidotartam)+)> +    <!ELEMENT tracktitle ( #PCDATA ) > 
-    <!ELEMENT cim ( #PCDATA ) > +    <!ELEMENT duration ( #PCDATA ) >   
-    <!ELEMENT dalcim ( #PCDATA ) > +
-    <!ELEMENT idotartam ( #PCDATA ) >   +
 ]> ]>
-```+</sxh>
  
 **Syntactically correct XML**: **Syntactically correct XML**:
  
-```xml+<sxh xml>
 <album> <album>
-    <cim>Title 1</cim+    <title>Title 1</title
-    <cim>Subtitle</cim+    <title>Subtitle</title
-    <dalcim>Track Title 1</dalcim+    <tracktitle>Track Title 1</tracktitle
-    <idotartam>3.42</idotartam+    <duration>3.42</duration
-    <dalcim>Track Title 2</dalcim+    <tracktitle>Track Title 2</tracktitle
-    <idotartam>2.32</idotartam>+    <duration>2.32</duration>
 </album> </album>
-```+</sxh>
  
-#### Example: A library may contain **books** (zero or more):+----
  
-```dtd +==== Example: A library may contain **books** (zero or more)==== 
-<!DOCTYPE adathordozo + 
-    <!ELEMENT konyvtar (konyv*) > +<sxh> 
-    <!ELEMENT konyv (szerzocim) > +<!DOCTYPE datastorage  
-    <!ELEMENT szerzo ( #PCDATA ) > +    <!ELEMENT library (book*) > 
-    <!ELEMENT cim ( #PCDATA ) >   +    <!ELEMENT book (authortitle) > 
 +    <!ELEMENT author ( #PCDATA ) > 
 +    <!ELEMENT title ( #PCDATA ) >   
 ]> ]>
-```+</sxh>
  
 **Syntactically correct XML**: **Syntactically correct XML**:
  
-```xml +<sxh xml> 
-<konyvtar+<library
-    <konyv+    <book 
-        <szerzo>Orwell, George</szerzo+        <author>Orwell, George</author
-        <cim>1984</cim+        <title >1984</title 
-    </konyv+    </book
-    <konyv+    <book
-        <szerzo>Brown, Dan</szerzo+        <author>Brown, Dan</author
-        <cim>The Da Vinci Code</cim+        <title >The Da Vinci Code</title 
-    </konyv+    </book 
-</konyvtar+</library
-```+</sxh> 
 + 
 +===== Defining Attributes in DTD ===== 
 + 
 +If a class has an attribute such as "number of students," it can be specified as follows: 
 + 
 +<sxh> 
 +<!ELEMENT class (student *) > 
 +<!ATTLIST class number CDATA #REQUIRED> 
 +</sxh> 
 + 
 +Attributes can be: 
 +- **#IMPLIED**: not mandatory 
 +- **#REQUIRED**: mandatory 
 +- **#FIXED**: fixed value 
 + 
 +=== Specifying a Default Attribute Value == 
 + 
 +Example: 
 + 
 +<sxh> 
 +<!ATTLIST paymentType type CDATA "bankTransfer"> 
 +</sxh 
 + 
 +The XML could look like this: 
 + 
 +<sxh> 
 +<paymentType/> or <paymentType type="bankTransfer"> 
 +</sxh> 
 + 
 +=== Enumerated Values === 
 + 
 +**Syntax**: 
 +<sxh> 
 +<!ATTLIST element-name attribute-name (eval | eval | ..) default-value> 
 +</sxh> 
 + 
 +**DTD Example**: 
 +<sxh> 
 +<!ATTLIST payment type (check | cash) "cash"> 
 +</sxh> 
 + 
 +**XML Example**: 
 +<sxh xml> 
 +<payment type="check"/> or <payment type="cash"/> 
 +</sxh> 
 + 
 +==== Complex DTD Example for a Hypothetical Mail Processing System ==== 
 + 
 +**Task**: Provide an XML example that satisfies the following DTD: 
 + 
 +<sxh> 
 +<!ELEMENT mails (email*, postcard*)> 
 +<!ELEMENT email (address, sender, message?, attachment?)> 
 +<!ELEMENT postcard (address, sender?, message?)> 
 +<!ELEMENT address (name, postalcode, city, country)> 
 +<!ATTLIST address nick CDATA #IMPLIED> 
 +<!ATTLIST sender nick CDATA #IMPLIED> 
 +<!ATTLIST attachment type CDATA #REQUIRED> 
 +<!ATTLIST postcard scanimage CDATA #IMPLIED> 
 +<!ATTLIST sender name CDATA #REQUIRED> 
 +</sxh> 
 + 
 +=== A Possible XML for the given DTD === 
 + 
 +<sxh xml> 
 +<mails> 
 +    <email> 
 +        <address nick="Alice">alice@usa.com</address> 
 +        <sender nick="Bob">bob@jp.com</sender> 
 +        <message>Hash code</message> 
 +        <attachment type="text/doc"></attachment> 
 +    </email> 
 +    <postcard scanimage="kep.jpg"> 
 +       <address> 
 +         <name>John Doe</name> 
 +         <postalcode>1234</postalcode> 
 +         <city>Miskolc</city> 
 +         <country>Hungary</country> 
 +       </address> 
 +       <sender name="Bob Cat" /> 
 +       <message>Happy Name Day</message> 
 +    </postcard> 
 +</mails> 
 +</sxh>
  
 +This provides an example of how attributes, including mandatory, optional, and default values, can be defined in a DTD and represented in an XML document.
tanszek/oktatas/techcomm/dtd.1728322821.txt.gz · Last modified: 2024/10/07 17:40 by knehez