xml dtd

13
XML DTD BY SANA MATEEN

Upload: sana-mateen

Post on 21-Mar-2017

58 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Xml dtd

XML DTD

BYSANA MATEEN

Page 2: Xml dtd

XML DTD• An XML document may have an optional DTD, which defines the

document’s grammar. Since the DTD defines the XML document’s grammar, we can use an

XML parser to check that if an XML document conforms to the grammar defined by the DTD.

• The purpose of a DTD is to define the legal building blocks of an XML document.

• Terminology for XML: -- well-formed: if tags are correctly closed. -- valid: if it has a DTD and conforms to it.

Validation is useful in data exchange.

Page 3: Xml dtd

• A DTD can be declared inside the XML document, or as an external reference.

• 1) Internal DTD This is a example of a simple XML document with an internal DTD:

The DTD a is interpreted like this:!DOCTYPE tutorials defines that the root element of this document is tutorials!ELEMENT tutorials defines that the tutorials element contains minimum one occurrence of child element.!ELEMENT tutorial defines that the tutorials element must contain two element name,url.!ELEMENT name defines the to element to be of type "#PCDATA"!ELEMENT url defines the from element to be of type "#PCDATA”

Page 4: Xml dtd
Page 5: Xml dtd

EXTERNAL DTD

• If the DTD is declared in an external file, the <!DOCTYPE> definition must contain a reference to the DTD file:

• The keyword SYSTEM indicates that it's a private DTD

Page 6: Xml dtd
Page 7: Xml dtd

DTD - XML Building Blocks• The main building blocks of both XML and HTML documents are elements.• Seen from a DTD point of view, all XML documents are made up by the

following building blocks:• Elements• Attributes• Entities• PCDATA• CDATA• Entities• Some characters have a special meaning in XML, like the less than sign (<) that

defines the start of an XML tag.• Most of you know the HTML entity: "&nbsp;". This "no-breaking-space" entity

is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser.

• The following entities are predefined in XML:

Page 8: Xml dtd

PCDATA and CDATA

• PCDATA• PCDATA means parsed character data.• Think of character data as the text found between the start tag and the end

tag of an XML element.• PCDATA is text that WILL be parsed by a parser. The text will be

examined by the parser for entities and markup.• However, parsed character data should not contain any &, <, or >

characters; these need to be represented by the &amp; &lt; and &gt; entities, respectively.

• CDATA means character data.• CDATA is text that will NOT be parsed by a parser. Tags inside the text

will NOT be treated as markup and entities will not be expanded.

Page 9: Xml dtd

DTD ELEMENTS

• In a DTD, elements are declared with an ELEMENT declaration.• Declaring Elements• In a DTD, XML elements are declared with the following syntax:

• Empty Elements• Empty elements are declared with the category keyword EMPTY:

Page 10: Xml dtd
Page 11: Xml dtd

DTD - Attributes• In a DTD, attributes are declared with an ATTLIST declaration.• Declaring Attributes• An attribute declaration has the following syntax:• <!ATTLIST element-name attribute-name attribute-type attribute-value>

DTD example:

<!ATTLIST payment type CDATA "check">

XML example:

<payment type="check" />

Page 12: Xml dtd

The attribute-value can be one of the following:

DTD - Entities

1. Entities are used to define shortcuts to special characters.2. Entities can be declared internal or external.3. An Internal Entity Declaration

4. <!ENTITY entity-name "entity-value">

Page 13: Xml dtd