XML Attributes


An attribute is placed within the opening tag of the element.  The attributes in XML are very similar to those in HTML except those in XML are required to have values.  Examples of both incorrect and correct ways to insert attributes are shown in the examples below.


<student enrolled>





Example: CORRECT

<student enrolled=”true”>





Both double quote (“) and single quote (‘) are valid in XML documents and it is up to the creator to determine which ones to use.  There are a few instances where one type of quotation may make more sense than the other.  For example, if the attribute value has its own set of double quotes, it may make more sense to use a single quote to close the attribute.

When using attributes, there are a few drawbacks that you should keep in mind. Attributes cannot do the following:

  • Contain multiple values like elements
  • Contain tree structures like elements
  • Easily be expanded for future changes

In addition to these drawbacks, attributes can sometimes be difficult to maintain and read.  It is a good practice to use elements to present data and attributes to present data that is not relevant to data.  Also, if using metadata, it can be stored as attributes rather than elements.

This entry was posted in XML Tutorial. Bookmark the permalink.

9 Responses to XML Attributes

  1. you can say that alternative medicine is cheaper too and usually comes from natural sources.

  2. Yay google is my queen assisted me to find this outstanding site! .

  3. 691893 687837Awesome read , Im going to spend a lot more time researching this topic 980615

  4. read review says:

    959199 780893noutati interesante si utile postate pe blogul dumneavoastra. dar ca si o paranteza , ce parere aveti de inchiriere vile vacanta ?. 476527

  5. Ha, here from yahoo, this is what i was searching for.

  6. I conceive you have mentioned some very interesting details , appreciate it for the post.

  7. 518707 768729An really intriguing read, I may possibly possibly not agree completely, but you do make some quite valid points. 993060

  8. Intresting, will come back here later too.

  9. العراق says:

    286095 105941Hey there! Great post! Please when all could see a follow up! 431

Leave a Reply

Your email address will not be published.