Wattle Software - producers of XMLwriter XML editor
 Home | Search | Site Map 
XMLwriter
 Screenshots
 Features
 About Latest Version
 Awards & Reviews
 User Comments
 Customers
Download
 Download XMLwriter
 Download Plug-ins
 Download Help Manual
 MSXML Updates
 Downloading FAQ
Buy
 Buy XMLwriter
 Pricing
 Upgrading
 Sales Support
 Sales FAQ
Support
 Sales Support
 Technical Support
 Submit a Bug Report
 Feedback & Requests
 Technical FAQ
Resources
 XML Links
 XML Training
 XMLwriter User Tools
 The XML Guide
 XML Book Samples
Wattle Software
 About Us
 Contact Details
ATTLIST Declaration

Attributes are additional information associated with an element typeglossary. They are intended for interpretation by an application. The ATTLIST declarations identify which element types may have attributes, what type of attributes they may be, and what the default value of the attributes are.

<!ATTLIST element_name attribute_name attribute_type default_value>
.
.
.
<element attribute_name="attribute_value">

where:

  • element_name: name of the element to which the attribute applies.
Example:
<?xml version="1.0"?>
<!DOCTYPE image [
  <!ELEMENT image EMPTY>
  <!ATTLIST image height CDATA #REQUIRED>
  <!ATTLIST image width CDATA #REQUIRED>
]>
<image height="32" width="32"/>

Rules:

  • All attributes used in an XML document must be declared in the Document Type Definition (DTD) using an Attribute-List Declarationvalidity constraint.
  • Attributes may only appear in startglossary or emptyglossary tagswell-formedness constraint.
  • The keyword ATTLIST must be in upper casewell-formedness constraint.

Note:

There are three main attribute types; a string type, tokenized types, and enumerated types. They are classified as follows.

String Attribute Type: Attribute Description:
CDATA CDATA stands for character data, that is, text that does not form markup. See example.

Tokenized Attribute Type: Attribute Description:
ID ID is a unique identifier of the attribute.IDs of a particular value should not appear more than once in an XML documentvalidity constraint. An element type may only have one ID attributevalidity constraint. An ID attribute can only have an #IMPLIED or #REQUIRED default valuevalidity constraint. The first character of an ID value must be a letter, '_', or ':'validity constraint. See example.
IDREF IDREF is used to establish connections between elements. The IDREF value of the attribute must refer to an ID value declared elsewhere in the documentvalidity constraint. The first character of an ID value must be a letter, '_', or ':'validity constraint. See example.
IDREFS Allows multiple ID values separated by whitespacevalidity constraint.
ENTITY ENTITYs are used to reference data that act as an abbreviation or can be found at an external location. The first character of an ENTITY value must be a letter, '_', or ':'validity constraint. See example.
ENTITIES Allows multiple ENTITY names separated by whitespacevalidity constraint. See example.
NMTOKEN The first character of an NMTOKEN value must be a letter, digit, '.', '-', '_', or ':'validity constraint. See example.
NMTOKENS Allows multiple NMTOKEN names separated by whitespacevalidity constraint.

Enumerated Attribute Type: Attribute Description:
NOTATION NOTATIONs are useful when text needs to be interpreted in a particular way, for example, by another application. The first character of a NOTATION name must be a letter, '_', or ':'validity constraint. See example.
Enumerated Enumerated attribute types allow you to make a choice between different attribute values. The first character of an Enumerated value must be a letter, digit, '.', '-', '_', or ':'validity constraint. See example.

CDATA Example:
<?xml version="1.0"?>
<!DOCTYPE image [
  <!ELEMENT image EMPTY>
  <!ATTLIST image height CDATA #REQUIRED>
  <!ATTLIST image width CDATA #REQUIRED>
]>
<image height="32" width="32"/>
ID Example:
<?xml version="1.0"?>
<!DOCTYPE student_name [
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no ID #REQUIRED>
]>
<student_name student_no="a9216735">Jo Smith</student_name>
IDREF Example:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE lab_group [
  <!ELEMENT lab_group (student_name)*>
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no ID #REQUIRED>
  <!ATTLIST student_name tutor_1 IDREF #IMPLIED>
  <!ATTLIST student_name tutor_2 IDREF #IMPLIED>
]>
<lab_group>
  <student_name student_no="a8904885">Alex Foo</student_name>
  <student_name student_no="a9011133">Sarah Bar</student_name>
  <student_name student_no="a9216735"
    tutor_1="a9011133" tutor_2="a8904885">Jo Smith</student_name>
</lab_group>
ENTITY Example:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE experiment_a [
  <!ELEMENT experiment_a (results)*>
  <!ELEMENT results EMPTY>
  <!ATTLIST results image ENTITY #REQUIRED>
  <!ENTITY a SYSTEM
    "http://www.university.com/results/experimenta/a.gif">
]>
<experiment_a>
  <results image="a"/>
<experiment_a>
ENTITIES Example:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE experiment_a [
  <!ELEMENT experiment_a (results)*>
  <!ELEMENT results EMPTY>
  <!ATTLIST results images ENTITIES #REQUIRED>
  <!ENTITY a1 SYSTEM
    "http://www.university.com/results/experimenta/a1.gif">
  <!ENTITY a2 SYSTEM
    "http://www.university.com/results/experimenta/a2.gif">
  <!ENTITY a3 SYSTEM
    "http://www.university.com/results/experimenta/a3.gif">
]>
<experiment_a>
  <results images="a1 a2 a3"/>
</experiment_a>
NMTOKEN Example:
<?xml version="1.0"?>
<!DOCTYPE student_name [
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no NMTOKEN #REQUIRED>
]>
<student_name student_no="9216735">Jo Smith</student_name>
NOTATION Example:
<?xml version="1.0"?>
<!DOCTYPE code [
  <!ELEMENT code (#PCDATA)>
  <!NOTATION vrml PUBLIC "VRML 1.0">
  <!ATTLIST code lang NOTATION (vrml) #REQUIRED>
]>
<code lang="vrml">Some VRML instructions</code>
Enumerated Example:
<?xml version="1.0"?>
<!DOCTYPE ToDoList [
  <!ELEMENT ToDoList (task)*>
  <!ELEMENT task (#PCDATA)>
  <!ATTLIST task status (important|normal) #REQUIRED>
]>
<ToDoList>
  <task status="important">This is an important
    task that must be completed</task>
  <task status="normal">This task can wait</task>
</ToDoList>

The "default_value" signifies whether an attribute is required or not, and if not, what default value should be displayed. The possible default values are listed in below.

Default Value: Description:
#REQUIRED The attribute must always be includedvalidity constraint.
#IMPLIED The attribute does not have to be included.
#FIXED "Default_Value" The attribute must always have the default value that is specifiedvalidity constraint. If the attribute is not physically added to the element tag in the XML document, the XML processor will behave as though the default value does exist. The first character of a default value can be any character except for '&', '<', '"'. It can also be an entity reference (i.e. '&Name;'), or a character referencevalidity constraint. See example.

Default Value Examples:
<?xml version="1.0"?>
<!DOCTYPE ToDoList [
  <!ELEMENT ToDoList (task)*>
  <!ELEMENT task (#PCDATA)>
  <!ATTLIST task status (important|normal) "normal">
]>
<ToDoList>
  <task status="important">This is an important task.</task>
  <task>This is by default a task that has a normal status.</task>
</ToDoList>
<?xml version="1.0"?>
<!DOCTYPE ToDoList [
  <!ELEMENT ToDoList (task)*>
  <!ELEMENT task (#PCDATA)>
  <!ATTLIST task status NMTOKEN #FIXED "monthly">
]>
<ToDoList>
  <task>go to the bank</task>
  <task>pay the phone bill</task>
</ToDoList>



Predefined attributes:

Predefined Attributes: Description:
xml:lang Defines the language code in which the content of the element is written in. The attribute values of xml:lang should follow ISO-639 if they are two-letter codes, and ISO-3166 if they contain two-letter subcodes. Language identifiers registered with the IANAglossary should contain the prefix "I-" or "i-". Any privately used codes should contain the prefix "X-" or "x-".
xml:space Preserves white space within a document, that is, passes all white space to the application unchanged. Useful when displaying text such as program source code.

Example:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE document [
  <!ELEMENT document (description,code)>
  <!ELEMENT description (#PCDATA)>
  <!ATTLIST description xml:lang NMTOKEN #FIXED "en">
  <!ELEMENT code (#PCDATA)>
  <!ATTLIST code xml:space (default|preserve) "preserve">
]>
<document>
  <description xml:lang="en">
    The following section of code displays the menu of user
    choices and gets the user's request.
  </description>
  <code>
  do
    {
    do
      { disp_menu();
          scanf(" %d", &amp;ans);
      } while ((ans&lt;1) || (ans&gt;3));
  </code>
</document>


XML Guide TOC

XML Declaration
DOCTYPE Declaration & DTDs
ELEMENT Type Declaration
ATTLIST Declaration
ENTITY Declaration
NOTATION Declaration
CDATA Section
Processing Instruction
Conditional Section
Comments

Glossary

© Wattle Software 1998-2013. All rights reserved.