What is Attributes in XML

This topic fully describe about XML Attributes. After learn this you are able to understand how we can use XML Attributes.
  • 2126

 DTD Attributes in xml

 Attributes in xml  declared with the ATTLIST  declaration. with a different element that has the different work

For Example :

<!ATTLIST element-name attribute-name attribute-type default-value>
 

 example:

<!ATTLIST  payment  CDATA "check">

XML example:

<payment ="check" />

 

Note: Attributes  can be several type

  Attribute Type  Attributes Description
CDDATA  The value is character data
ID  The value is unique id
IDRef  The value in the id of other element
IDREFS  The value in the id  of list of other ids
NMTOKEN  The value is a valid xml name
XML:  The value is the predefine or default  xml value
Entities  The values is the list of entitles

The default value can be also . These are following

Value description
value  default value of the attributes
#REQUIRED  The value must be required
#IMPLIED  The Attribute is not required
#FIXED value  Attribute value fixed

 Default Attribute value  

DTD:
<!ELEMENT square EMPTY>
<!ATTLIST height width CDATA "0">

Valid XML:
<square height="200" />  

#REQUIRED

 <!ATTLIST element-name attribute-name attribute-type #REQUIRED>

Note : - this is the declaration of #REQUIRED

 Example:

DTD:
<!ATTLIST personal  number CDATA #REQUIRED>

Valid XML:
<personal  number="677" />

Invalid XML:
<personal/>

#IMPLIED

<!ATTLIST element-name attribute-name attribute-type #IMPLIED>

Note : this is only declaration part of #IMPLIED

Example:

DTD:
<!ATTLIST  fax no CDATA #IMPLIED>

Valid XML:
<fax no="555-9995588" />

Valid XML:
<fax />

#FIXED value

<!ATTLIST element-name attribute-name attribute-type #FIXED "value">

Note: This is only the declaration portion of the #FIXED value

Example :

DTD:
<!ATTLIST company CDATA #FIXED "MCN  Private solution">

Valid XML:
< company="MCN  private solution" />

Invalid XML:
< company="dotnet factor" />

Enumerated Attribute Values

How to declared it

<!ATTLIST element-name attribute-name (en1|en2|..) default-value>

Example :

DTD:
<!ATTLIST  pay type (check|cash) "cash">

XML example:
<pay type="check" />
or
<pay type="cash" />

Enumerated attributes value must be one of the legal  value ( check or cash).

further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.