tanszek:oktatas:techcomm:dtd
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tanszek:oktatas:techcomm:dtd [2024/10/07 17:33] – created knehez | tanszek:oktatas:techcomm:dtd [2025/12/02 08:01] (current) – knehez | ||
|---|---|---|---|
| Line 14: | Line 14: | ||
| === Internal declaration === | === Internal declaration === | ||
| - | < | + | < |
| - | < | + | < |
| .... | .... | ||
| ]> | ]> | ||
| Line 21: | Line 21: | ||
| === External URI === | === External URI === | ||
| - | < | + | <sxh> |
| < | < | ||
| </ | </ | ||
| === External file === | === External file === | ||
| - | < | + | < |
| - | < | + | < |
| </ | </ | ||
| The DTD defines the structure and rules that an XML document must follow to be considered valid. | The DTD defines the structure and rules that an XML document must follow to be considered valid. | ||
| + | |||
| + | ==== DTD Through Examples ==== | ||
| + | |||
| + | Here is a DTD file named '' | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <sxh xml> | ||
| + | <?xml version = " | ||
| + | < | ||
| + | |||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | In the XML structure, a **comma** indicates the required order of elements: | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | ]> | ||
| + | </ | ||
| + | |||
| + | <sxh xml> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | The **pipe symbol `|`** expresses an **either-or** relationship. For example, the storage device can be either a **pendrive** or an **SSD**, but not both: | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | ]> | ||
| + | </ | ||
| + | |||
| + | <sxh xml> | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | There are three ways to express **frequency**: | ||
| + | |||
| + | ^ Symbol ^ Meaning ^ | ||
| + | | '' | ||
| + | | '' | ||
| + | | ''?'' | ||
| + | |||
| + | ==== Example: A music CD contains **tracks**: ==== | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | ]> | ||
| + | </ | ||
| + | |||
| + | <sxh xml> | ||
| + | <CD> | ||
| + | < | ||
| + | < | ||
| + | </CD> | ||
| + | </ | ||
| + | ---- | ||
| + | ==== Example: An album has at least one title, followed by at least one **track title** and **duration**: | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | ]> | ||
| + | </ | ||
| + | |||
| + | **Syntactically correct XML**: | ||
| + | |||
| + | <sxh xml> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Example: A library may contain ' | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | ]> | ||
| + | </ | ||
| + | |||
| + | **Syntactically correct XML**: | ||
| + | |||
| + | <sxh xml> | ||
| + | < | ||
| + | <book > | ||
| + | < | ||
| + | <title > | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | <title >The Da Vinci Code</ | ||
| + | </book > | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Defining Attributes in DTD ===== | ||
| + | |||
| + | If a class has an attribute such as " | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Attributes can be: | ||
| + | |||
| + | * **# | ||
| + | * **# | ||
| + | * **#FIXED**: fixed value | ||
| + | |||
| + | === Specifying a Default Attribute Value == | ||
| + | |||
| + | Example: | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | </sxh | ||
| + | |||
| + | The XML could look like this: | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | === Enumerated Values === | ||
| + | |||
| + | **Syntax**: | ||
| + | <sxh> | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | **DTD Example**: | ||
| + | <sxh> | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | **XML Example**: | ||
| + | <sxh xml> | ||
| + | <payment type=" | ||
| + | </ | ||
| + | |||
| + | ==== Complex DTD Example for a Hypothetical Mail Processing System ==== | ||
| + | |||
| + | **Task**: Provide an XML example that satisfies the following DTD: | ||
| + | |||
| + | <sxh> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | === A Possible XML for the given DTD === | ||
| + | |||
| + | <sxh xml> | ||
| + | < | ||
| + | < | ||
| + | <address nick=" | ||
| + | <sender nick=" | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | 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.1728322384.txt.gz · Last modified: 2024/10/07 17:33 by knehez
