XML Tutorial (2) - XML ​​Element and XML Attribute Value

xiaoxiao2021-03-06  58

The XML element is scalable. This means that the XML document content can store more data information at any time by extension.

E.G:

code:

Shooting your salary <口 taste> A spotted

At this time, if we want to output some of this data through our application or other things, such as , , will be the following results (output result is due to your output OK, XML data content itself does not change)

E.G:

About lobster dinner

Price: shot your salary

Identity: a spot

Side effect: a stomach

Welcome to taste (this example is a false example, in addition to the other, all of the other, do not mess with your head)

When the output we suddenly discovered, what should I do with new data to the data?

Very simple, directly sandwiched in XML data.

E.G:

code:

Shooting your salary <口>> Can you replace it with live lobster? still have a good money, then there is money to pay for the treatment of gastrointestinal medical expenses after the time?

Some people will ask "What adding data will affect the false example of the previous?". Oh, no!

After we add data, the imperative example above still outputs the same result. And you can also display our newly added data by changing the application.

Inter-XML element relationship, because the XML element must specify the root element, the elements below the root element are the child elements, mutual brothers elementary relationship, for data storage, make sure that child element content is related to root elements, and each brothers Elements It is also preferred to have logical associations.

XML element content, a complete XML file is determined by its ability to store data, and its content is declared in various elements, here, this content can be blank content, It is also possible to be simple text or single data, and can also be complex multiple data columns, or even other classification sub-elements.

XML element naming rules, similar to Java, C and other naming rules, can be English letters or Chinese as element name (can also be other languages, but must first ensure that your data read software can be supported), you can use numbers and letters The name starts, the name cannot appear in the name !!! You can use the function of the next line "_" to replace the space for detailed naming, and it is strictly forbidden in the name ":"

XML series tutorial third lecture - xml attribute value

The properties of the elements have appeared in the previous lecture.

E.G:

code:

.........

Among them, the value = "invaluable treasure" is the property value of the root element "My Story"

Then, what can the attribute value do? Attribute values ​​in XML can be used to add additional instructions for elements. In fact, we have already contacted attribute values ​​very early, and the frequency is very high, that is, in HTML Attribute value .eg:

Attribute value in HTML

~~~~~~~~~~~~~~~~~~~

The property value is used

In XML, we can also apply attribute values ​​to elements, but don't be too frequent. After all, XML is used to store and send data information, so its scalability is very important, we may always need to add to XML files. Data, although the use of attribute values ​​can be easily added to the element, it is very unfavorable to future maintenance and update ... Moreover, these things use the element to do it is the correct choice (therefore, I don't It is recommended to frequently use attribute values).

E.G:

Property value

code:

Do not use attribute values

code:

JSper Unknow None Jsper @ 371.NET

Obviously, frequent use attribute values ​​is difficult to maintain and update, and use attribute values ​​and a series of weaknesses ---

1. The attribute value cannot contain multiple values ​​(element can);

2, the attribute value is difficult to expand (take into account long-term intended);

3. The attribute value cannot be used to describe the structure content (the child element can be);

4, the property value is difficult to make a test through DTD (for the introduction of DTD, please look forward to the follow-up tutorial)

Maybe your grammar teacher told you a word "Is the rule has exceptions", which is also the same here ... After all, attribute value is not a place ^ _ ^. We can use the value to represent the same element. Different content. as follows

E.G:

code:

Flyingfish Neutral Unknown Here, we use numbers to distinguish element "My netizens", of course, you can also use other ways. For example, "Number =" No.1 "

转载请注明原文地址:https://www.9cbs.com/read-90965.html

New Post(0)