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.

2 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! .

Leave a Reply

Your email address will not be published.