Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the xml properties

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "what are the xml attributes", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the xml attributes" this article.

Like HTML, XML elements can be marked with element attributes at the beginning of the tag. Attributes usually contain some additional information about the element.

XML attribute

XML elements can have attributes.

You must remember the HTML code like this:

. Src is an attribute of the img element and provides additional information about the img element.

The attributes of an element in HTML (as well as in XML) provide additional information about the element.

The information provided by the letter is usually not part of the data. In the following example, the type is irrelevant to the data, but it is very important for the software that operates this element.

Computer.gif

Quote style "female" or "female'?"

Attribute values must be enclosed in quotation marks. Both single and double quotation marks can be used. For example, for a person's gender, the person element can be written as follows:

You can also write:

The above two writing methods are not different in general, and the use of double quotation marks is more common. However, single quotation marks must be used in some special cases, such as the following example:

Using child elements or attributes

Data can be stored either in child elements or in attributes.

Take a look at the following example:

AnnaSmithfemaleAnnaSmith

In the first example, sex is an attribute, and in the second example, sex is a child element. Both examples provide the same information.

There is no ready-made rule for when to use attributes and when to use child elements. My experience is that attributes can be quite convenient in HTML, but in XML, you'd better avoid using them.

My favorite style

I prefer to store data in child elements.

The following three XML documents contain the same information:

The first example uses the data attribute:

ToveJaniReminderDon't forget me this weekend!

The second example uses the data element:

12/11/99ToveJaniReminderDon't forget me this weekend!

The third example uses the extended data element: (this is the style I recommend):

121199ToveJaniReminderDon't forget me this weekend!

Avoid using attributes?

Should you avoid using attributes?

Here are some problems caused by the use of attributes:

An attribute cannot contain multiple values (child elements can).

Property is not easy to extend.

Attribute cannot describe the structure (child elements can).

Properties are difficult to handle by program code.

Property values are difficult to test through DTD.

If you use attributes to store data, the XML document you write must be difficult to read and manipulate. Try to use elements to describe data, and only attributes to describe additional information that has little to do with the data.

Don't follow the example below (if you do that, you don't understand the above point of view).

Exception to the attribute rule

There are always exceptions to the rule.

There is also an exception to my rule on attributes:

Sometimes you should design an ID reference for an element through which you can reference and access specific XML elements, just like the name and id attributes in HTML. Take a look at the following example:

ToveJaniReminderDon't forget me this weekend!JaniToveRe: ReminderI will not!

In the above example, the ID property is equivalent to a counter, or a unique identifier, that identifies different note information in the XML document, which is not part of the note information.

What we are trying to explain to the reader is that metadata (data related to data) should be stored as attributes, while the data itself should be stored as elements.

The above is all the content of this article "what are the xml attributes?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report