Vujsa is 100% correct, although he did not get at the main reason for the difference. The reason why both exist comes down to the
DOM and
XML requirements. To properly parse and navigate an XML document for more than simple stylistic ends, which is one of the plusses of XML, sometimes information about the items must be stored in the element itself, hence the purpose of the id and class attributes. The id attribute, as vujsa explained, identifies one specific entity. This is useful because instead of having to define a person as such in XML:
CODE
<person>
<name>
vizskywalker
</name>
<personaldata>
data
</personaldata>
</person>
You can create it like so:
CODE
<person id="vizskywalker">
<personaldata>
data
</personaldata>
</person>
In this oversimplified example, it doesn't seem to make much difference, but when writing scripts such as javascripts to handle the XML document, being able to easily find and identify one entity without having to go through the whole tree it is connected to can be very important.
Other than stylistic purposes, the class attribute also has other uses in XML used for non-XHTML type XML documents:
CODE
<animal class="person" id="vizskywalker">
<communication>
english
</communication>
</animal>
<animal class="person" id="vujsa">
<communication>
english
</communication>
</animal>
<animal class="dog">
<communication>
bark
</communication>
</animal>
As you can see, one type of element, the animal element, has many subgroups. Rather than define a new element to determine the type of animal, you can use the class attribute. You can even mix and match id and class attributes to determine the type of animal and which specific animal of that type.
~Viz
Comment/Reply (w/o sign-up)