DTD Building Blocks : XML
In the last chapter we have learnt basics of XML DTD. In this chapter we will be learning the different parts of DTD or different building blocks of the XML DTD.
Main XML DTD Building Blocks :
Building Block | Explanation |
---|---|
Elements | Main nodes and main building block |
Attributes | Extra information about element. |
Entities | Special characters in XML |
PCDATA | parsed character data |
CDATA | character data |
A. XML Elements :
In HTML and XML, Elements are main building blocks.Consider the following XML document -
<Book pages="100"> <name>Learn XML</name> <author>Pritesh</author> <type>Scripting</type> </Book>
In the above example, XML elements are -
Element | Name of the Element |
---|---|
Root Element | Book |
Child Elements | name,author,type |
Now each element in the XML document can contain either another element or data.
Name of the element | What data it stores ? |
---|---|
Book | This XML element stores 3 elements in it |
name | This XML stores Textual data |
author | This XML stores Textual data |
type | This XML stores Textual data |
B. XML Attributes :
XML Attribute provides some kind of extra information about XML element. Attributes are kind of name and value pair which provides some information of element.
Consider the following example -
<Book pages="100" type="script"> <name>Learn XML</name> <author>Pritesh</author> </Book>
Now in this example -
<Book pages="100" type="script">
Name | Element/Attribute ? | Attribute value |
---|---|---|
Book | Element | - |
pages | Attribute | 100 |
type | Attribute | script |
C. XML Entities :
We know that XML tags are written inside the pair of < and >. So problem occures if we put these characters as textual data inside the XML.
So some characters which are having special meaning in the XML document are called as entities. XML provides list of following entities -
Entity References | Character |
---|---|
< | < |
> | > |
& | & |
" | “ |
' | ‘ |
D. PCDATA / CDATA :
PCDATA | CDATA |
---|---|
PCDATA means parsed character data. | CDATA means character data. |
Generally used for Elements | Generally used for Attributes |
PCDATA is text that will be parsed by a parser | CDATA is text that will not be parsed by a parser |
Tags inside the text will be treated as markup and entities will be expanded | Tags inside the text will NOT be treated as markup and entities will not be expanded |