|
Summary
Because the DTD or schema is vital to the success of XML, this article provides guidelines for designing a DTD or schema. Even if you are not designing a DTD or schema, it is worthwhile to understand the rationale behind their design, since it is the structure of XML data that gives it meaning.
Tips for Designing an XML DTD or Schema
XML transfers information between two parties, whether human or machine. Just as two people must know the same language, both parties must speak the same XML dialect. The dialect, defined in the DTD (data type definition) or schema, is the vocabulary and grammar used to describe the information being transferred.
The producer and the processor of XML information must share a common DTD or schema. Because the DTD or schema is vital to the success of XML, this article provides guidelines for designing a DTD or schema. Even if you are not designing a DTD or schema, it is worthwhile to understand the rationale behind their design, since it is the structure of XML data that gives it meaning. This structure changes a random sequence of unintelligible words to speech, that is, it transforms data to information.
When designing a DTD or schema for XML data, analyze the nature of the data and how it is created and processed. Consider how data is stored in a relational database, with a clearly defined structure of records, fields and tables.
Before you begin your design, decide whether to store data as the value of an attribute or as a text element (even if numeric) within tags. Generally, it is better to store data in elements, as this approach is more flexible when used with XSL. (XSL is a specification for transforming XML to HTML or some other XML structure.)
Be careful not to design solely from a developer's perspective. Consider who produces the XML data. If it is produced and processed programmatically, a developer-friendly perspective is appropriate. In fact, XML for B2B transactions should be designed from this perspective to generate fast, reliable and efficient transfer of information. However, if a human will author or read the XML data, consider those needs when designing a DTD or schema. Elements and Attributes
An attribute is the name-value pair that immediately follows a tag name. An element is a tag along with its attributes and all the text and elements that it encloses. Elements within another element are called child elements. Consider the following example.
<tag_name attr_name1=value1 attr_name2=value2> <child_tag attr_name3=value3 /> <child_with_text>This is some text</child_with_text> This text is part of the tag_name element </tag_name>
As seen in this illustration, the tags are tag_name, child_tag and child_with_text. The attribute attr_name1 has a value of value1. The element, tag_name, consists of the following attributes and child elements:
Attributes: attr_name1, attr_name2
Child Elements: child_tag, child_with_text
Note that, in XML, every attribute value must be quoted with single (') or double quotes (). Also, every tag must have a closing tag or end with />. Since the child_tag element has no child elements or text, the tag ends with /> instead of a closing tag, for example, </child_tag>.
Widespread adoption of XML technology depends on DTD and schema designs that provide a structure convenient for humans. In other words, people will use XML only if it is easy and solves a problem.
Excepts from XML Unlocks Information: How XML Accommodates Human-Authored Content
| Further additional information | |
Updating comments...
Updating comments...
|