The Attributes of an XML Element |
|
Introduction |
When studying XML elements we saw how they constituted the main objects of an XML document. We also saw that an element could be nested inside of another element. Instead of nesting an element, you can transform the nested element into being part of the nesting element and thereby giving away its element qualities. This is the basis of an attribute. An attribute is a value that is created as part of an element, making that value different from the value of a regular element. There are similarities and differences between an element and an attribute. |
The element and the attribute have these in common:
The differences between an element and an attribute are:
An attribute must be created inside the start-tag of an element. To manually create an attribute, type the left angle bracket of the element, followed by the name of the element, an empty space, and the name of the attribute. The name follows the same rules we defined for names in XML. An attribute should have a value that can be used to distinguish it. To specify the name of an attribute, assign a value as a string to its name. Imagine you have an ISBN element as a child of a Video element as follows: <Video> <ISBN>0-7888-1623-3</ISBN> </Video> In this case, since ISBN is simply a child of the Video element, you can change the ISBN element to become an attribute of the Video element as follows: <Video ISBN="0-7888-1623-3"> Now, ISBN is an attribute of the Video element. |
|
||
Previous | Copyright © 2006-2016, FunctionX, Inc. | Next |
|