In
XML tags we can also define XML tag attributes. Like in
HTML suppose we use
the
HTML table tag then in element table we can also define the border, table width
and others also. Same convention we can also follow in XML with tag attributes
and these attributes are used to provide additional information about tags.
Like...
Note
on above XML Attribute example instead of a separate tag for Gender we use employee tag
attribute "gender". The major rule for attribute values is
to be enclosed in quotes always, either in single quotes or double quotes, any one can be used.
As shown in above we use single quote to assign value to gender attribute. We
can also use it as
<employee gender="m"> convention for using XML Attributes..
The preference in XML is to use the XML tags instead of XML attributes because it would
be quite difficult to handle XML attributes in other applications that's why the
preference is to use XML elements or tags for the replacement of XML Attributes.
Like the below example.
Because the
XML attributes make an XML document more complex and on the application ends it is
quite complex and difficult to extract the value of an XML attribute as compare to
the XML elements. Because of this complexity in future the extensions will be focus
on elements not on attributes. Even when we saw the latest software's
available in market such as Oracle products Visual Studio dot net they all use the
XML
elements only no complex kind of XML attributes are used in those elements.
The other way is an element can be accrue more then one time but the attribute
we can define once not more then one for a single XML entity. XML Attributes can't
describe the structure of XML document but an element it self is a part of XML
document structure so the conclusion is of this section of XML Tutorial is that
we strongly appreciate and will also use XML Elements in our XML Tutorial to
explain any thing instead of XML Attributes.