Like HTML, the XML element re-labeled can be by the element properties.
Attributes typically contain additional information about elements.
XML attribute
XML elements can have properties.
You must remember such an HTML code:
. The SRC is the properties of the IMG element, providing additional information about the IMG element.
In HTML (the same in XML) The properties of the elements provide additional information of the elements.

The information provided by the letter is usually not part of the data. In the following example, the type and data are not related, but it is quite important to the software that operates this element.
Quote style "female" or 'female'?
The attribute value must be brought by quotation marks. Single quotes, double quotes can be used. For example, a person's gender, the Person element can write this:
You can also write this:
The above two ways are in general, and the use of double quotes is more common. However, in some special cases, single quotes must be used, such as the following example:
Use child elements or use properties
Data can be stored in child elements or in the properties.
Please see the example below:
persons>
persons>
In the first example, SEX is an attribute, in the second example, SEX is a child element. Both examples provide the same information.
When is the property, when do you use child elements, there is no ready-made rule, you can follow. My experience is that attributes may be very convenient in HTML, but in XML, you'd better avoid use.
I like the style
I am more willing to store data into child elements.
The following three XML documents contain the same information:
The first example uses the DATA attribute:
Note>
The second example uses the DATA element:
The third example uses an extended Data element: (this is the style I recommend):
date>
Note>
Avoid using properties?
Should you avoid the use of properties?
There are some problems that use attributes here:
Attributes cannot contain multiple values (sub-elements). Attributes are not easy to expand. Attributes cannot describe structures (child elements). The attribute is difficult to process the program code. The attribute value is difficult to test by DTD.
If you use properties to store data, then the written XML document must be difficult to read and operate. Try to describe the data as much as possible, using only attributes to describe additional information that is not large with data relationships.
Don't like the example below (if you do it, you haven't understood the above views).
To = "TOVE" from = "jani" Heading = "Reminder" Body = "Don't forget me this weekend!"> Note> Exceptions of attribute rules The rules always have exceptions. There is also an exception about the rules about attributes: Sometimes you should design an ID reference for an element, you can reference the specific XML element, just like the Name and ID attributes in HTML. Please see the example below:
Note>
Note>
messages>
In the above example, the id attribute is equivalent to a counter, or a unique identifier, identifies different note information in the XML document, and he is not part of the note information.
What we have to try to explain to the reader: metadata (data related to data) should store attributes, and the data itself should be stored in the form of an element.
