cancel
Showing results for 
Search instead for 
Did you mean: 

Use of attribute

former_member474221
Participant
0 Kudos

Hi

What is the use of attribute in the data type...why cannot we just create it as an element ?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

nabendu_sen
Active Contributor
0 Kudos

Elements can be parents of other elements and/or attributes and can be repeated within the same level of an XML document. They also usually have start and end tags. An element would look like:


Image


Attributes consist of a named pair attached to an element start-tag. An example of how an attribute is, "ID" at below:


Image


Attribute values must be enclosed in single or double quotes. Attribute names must be unique within a single element occurrence.


The decision to use Elements versus Attributes is mostly an architectural one; however, there are some key differences between Elements and Attributes:

Elements are used to encapsulate pieces of data, and attributes are generally used to provide accompanying information about an element, rather than to encapsulate raw data itself.

Read more: http://wiki.answers.com/Q/What_is_difference_between_elements_and_attributes_in_XML#ixzz2DOnCTqE6



1. Elements can occur more than once (repeating) within the same level, while attributes can only appear once within the same level, example:


It is okay to have:


Image


But it would be invalid to have:


Image


2. Elements can be defined to be in a certain order, while attributes can appear in any order.