DTD - Building Blocks
Elements:
Elements are the basic building blocks of an XML document. They represent the structure and content of the data. Here's an example of an XML element:
<book>
<title>Harry Potter and the Sorcerer's Stone</title>
<author>J.K. Rowling</author>
<year>1997</year>
</book>
In this example, <book>, <title>, <author>, and <year> are elements. Elements can have opening and closing tags (<element> and </element>) or be self-closing (<element/>) if they don't have any content.
Attributes:
Attributes provide additional information about an element. They are placed within the opening tag of an element. Here's an example:
<book genre="fantasy" language="English">
<title>Harry Potter and the Sorcerer's Stone</title>
<author>J.K. Rowling</author>
<year>1997</year>
</book>
In this example, genre and language are attributes of the <book> element. Attributes are specified as name-value pairs and are enclosed in quotes.
Entities:
Entities are used to represent special characters or reserved symbols in XML. They are predefined or custom-defined and help in escaping characters that have special meanings in XML. Here's an example using a predefined entity:
<description>This is an example of a <book> element.</description>
In this example, < represents the less-than symbol < and > represents the greater-than symbol >.
PCDATA:
PCDATA stands for "Parsed Character Data" and refers to the content within an XML element that will be parsed and interpreted by the XML parser. It can include text, numbers, symbols, and other characters. Here's an example:
<title>Harry Potter and the Sorcerer's Stone</title>
In this example, the text "Harry Potter and the Sorcerer's Stone" is PCDATA within the <title> element.
CDATA:
CDATA stands for "Character Data" and is used to include blocks of text that should be treated as plain character data without any parsing or interpretation by the XML parser. CDATA sections are enclosed within <![CDATA[ and ]]> markers. Here's an example:
<description><![CDATA[This is a CDATA section <b>without</b> parsing.]]></description>
In this example, the text "This is a CDATA section <b>without</b> parsing." is treated as raw character data and any HTML tags within it will not be parsed.