User Tools

Site Tools


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:46] – [DTD Through Examples] kneheztanszek:oktatas:techcomm:dtd [2024/10/07 17:57] (current) – [Complex DTD Example for a Hypothetical Mail Processing System] knehez
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**: ====
  
Line 129: Line 129:
 </album> </album>
 </sxh> </sxh>
 +
 +----
  
 ==== Example: A library may contain **books** (zero or more)==== ==== Example: A library may contain **books** (zero or more)====
Line 156: Line 158:
 </sxh> </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.1728323171.txt.gz · Last modified: 2024/10/07 17:46 by knehez