Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Dtd Attributes in XML

Dtd Attributes in XML

DTD Attributes in XML


What are DTD Attributes?

  • Attributes provide additional information about XML elements.

  • In a DTD, attributes are declared separately from elements using <!ATTLIST>.

  • You define which attributes an element can have, their types, and whether they are required or optional.


Syntax of Attribute Declaration in DTD

<!ATTLIST elementName  attributeName attributeType defaultDeclaration>

Common Attribute Types

Attribute TypeDescriptionExample
CDATACharacter data (any text)id CDATA #REQUIRED
IDUnique identifier (must be unique in XML document)id ID #REQUIRED
IDREFReference to an existing IDref IDREF #IMPLIED
IDREFSMultiple references (space-separated)refs IDREFS #IMPLIED
ENTITYReference to an unparsed entity
ENTITIESMultiple entity references
NMTOKENName token (valid XML name characters)token NMTOKEN #IMPLIED
NMTOKENSMultiple name tokens
Enumerated valuesList of possible values`status (new

Default Declarations

Default DeclarationMeaning
#REQUIREDAttribute must be provided
#IMPLIEDAttribute is optional
#FIXED "value"Attribute value is fixed and cannot be changed
"defaultValue"If attribute is missing, use this default value

Example DTD with Attributes

<!ELEMENT book (title, author)><!ATTLIST book  id ID #REQUIRED  genre CDATA #IMPLIED  status (available | checkedout | reserved) "available"><!ELEMENT title (#PCDATA)><!ELEMENT author (#PCDATA)>

Corresponding XML Example

<book id="b001" genre="fiction" status="checkedout">  <title>1984</title>  <author>George Orwell</author></book><book id="b002">  <title>Brave New World</title>  <author>Aldous Huxley</author></book>
  • The first <book> has all attributes.

  • The second <book> uses default "available" for status and has no genre.


Summary

ConceptDescription
<!ATTLIST>Defines attributes for an element
Attribute TypesCDATA, ID, IDREF, enumerations, etc.
Default ValuesRequired, optional, fixed, default

If you want, I can help you write a full XML + DTD file with attributes and validation examples!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql