In XML
<name =”John”>
is not syntactically correct. It should be something like this
<person name="John"></person>
Then
person
is called
element
and
name
is called the
attribute
of the element
person
. As said in the question the other way of doing this is
<person>
<name>John</name>
</person>
Here,
name
is the
child element
of the element
person
.
Both, give the information. There are no hard and fast rules regarding when to use as an
attribute
and when to use as
child element
. But, as a general the attribute can be used when the information concerned
describes something
about the element concerned, like an adjective describes about a noun. On the other hand an element can be used when the information concerned is like
data
.
The other difference is that if it is represented as an element then it can
nest
other elements and also can have
attributes
. But, if it is given as an attribute then it cannot have child elements and other attributes.
An explanation is given here
http://www.w3schools.com/dtd/dtd_el_vs_attr.asp[
^]
http://msdn.microsoft.com/en-us/library/7f0tkwcx(v=vs.80).aspx[
^]
I think it may be helpful.