DTD - Elements vs Attributes
Elements and attributes are two fundamental components of an XML document. They serve different purposes and have distinct characteristics:
Elements:
Elements define the structure and content of an XML document.
They are enclosed within opening and closing tags (<element> and </element>) or can be self-closing (<element/>) if they don't have any content.
Elements can contain other elements, text content (parsed character data), or a combination of both.
They represent the main building blocks of an XML document and organize the data hierarchy.
Elements can have child elements, allowing for nesting and hierarchical relationships.
They can occur multiple times within a document and can have various occurrences, including zero, one, or multiple instances.
<person>
<name>John Doe</name>
<age>25</age>
</person>
Attributes:
Attributes provide additional information about elements.
They are placed within the opening tag of an element and consist of name-value pairs.
Attributes define properties, characteristics, or metadata associated with an element.
They are used to describe specific aspects of an element's content or behavior.
Attributes are optional and can have default values or be required, depending on their declaration in the DTD or schema.
An element can have multiple attributes, each with its own name and value.
<person gender="male" occupation="engineer">
<name>John Doe</name>
<age>25</age>
</person>