​​​​​​​​XML Attributes​


​​​​​​​​​​​XML attributes can be defined as the extra information given by the coder/programmer about his tags. These attributes can be ​
​given by the side of the tag names.​
​For example,​
​​
​​
​​

    ​​​​​<student college=”Delhi College of Engg”>​​​​​​​​​
    ​​
    ​​
    ​​

​​​​​this is a student tag that also contains an attribute by the name of college. The attributes value is “Delhi College of ​
​Engg”. Remember to always enclose the attributes value in inverted commas (“”). This is the only rule for using ​
​attributes in XML.​
​But, I like many other XML developers would ask you rather to avoid using the attributes. Attributes are not included ​
​in the XML data. Use elements instead.​
​Example,​
​​
​​
​​

    ​​​​​<student id=”10234″>​​​​​​​​​
    ​​
    ​​
    ​​

​​​​​instead we can always use,​
​​
​​
​​

    ​​​​​<student>​​​​​​​​​
    ​​
    ​​
    ​​
    ​​​​​<id>10234</id>​​​​​​​​​
    ​​
    ​​
    ​​

​​​​​Thus, the above two tags are giving the same information but in a different approach. I would prefer the second one ​
​(it’s my choice !!).​
​Moreover, some things that you can enjoy with tags and elements and not with attributes are:​
​​
​​
​​

    ​​

  • ​​​​​attributes cannot contain multiple values (elements can as they can have a many tags in one tag)​​​​​​​​​
    ​​
    ​​
    ​​
  • ​​​​​attributes cannot contain tree structures (elements can as the XML elements exist in tree structures )​​​​​​​​​
    ​​
    ​​
    ​​
  • ​​​​​attributes are not easily expandable (for future changes, and elements can be extended very easily)​
Advertisements
Explore posts in the same categories: XML

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: